Skip to content

Commit 480a85c

Browse files
authored
Vb/pdate data row labeling priority gk sdk 413 (#1314)
2 parents e950690 + 52cefbf commit 480a85c

File tree

5 files changed

+67
-10
lines changed

5 files changed

+67
-10
lines changed

labelbox/schema/identifiables.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ def __init__(self, iterable, id_type: IdType):
2929
def __iter__(self):
3030
return iter(self._iterable)
3131

32+
def __repr__(self) -> str:
33+
return f"{self.__class__.__name__}({self._iterable})"
34+
3235

3336
class UniqueIds(Identifiables):
3437
"""

labelbox/schema/project.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,10 +1185,26 @@ def set_labeling_parameter_overrides(self, data) -> bool:
11851185
res = self.client.execute(query_str, {id_param: self.uid})
11861186
return res["project"]["setLabelingParameterOverrides"]["success"]
11871187

1188+
@overload
1189+
def update_data_row_labeling_priority(
1190+
self,
1191+
data_rows: DataRowIdentifiers,
1192+
priority: int,
1193+
) -> bool:
1194+
pass
1195+
1196+
@overload
11881197
def update_data_row_labeling_priority(
11891198
self,
11901199
data_rows: List[str],
11911200
priority: int,
1201+
) -> bool:
1202+
pass
1203+
1204+
def update_data_row_labeling_priority(
1205+
self,
1206+
data_rows,
1207+
priority: int,
11921208
) -> bool:
11931209
"""
11941210
Updates labeling parameter overrides to this project in bulk. This method allows up to 1 million data rows to be
@@ -1198,25 +1214,31 @@ def update_data_row_labeling_priority(
11981214
https://docs.labelbox.com/en/configure-editor/queue-system#reservation-system
11991215
12001216
Args:
1201-
data_rows (iterable): An iterable of data row ids.
1217+
data_rows: a list of data row ids to update priorities for. This can be a list of strings or a DataRowIdentifiers object
1218+
DataRowIdentifier objects are lists of ids or global keys. A DataIdentifier object can be a UniqueIds or GlobalKeys class.
12021219
priority (int): Priority for the new override. See above for more information.
12031220
12041221
Returns:
12051222
bool, indicates if the operation was a success.
12061223
"""
12071224

1225+
if isinstance(data_rows, list):
1226+
data_rows = UniqueIds(data_rows)
1227+
warnings.warn("Using data row ids will be deprecated. Please use "
1228+
"UniqueIds or GlobalKeys instead.")
1229+
12081230
method = "createQueuePriorityUpdateTask"
12091231
priority_param = "priority"
12101232
project_param = "projectId"
1211-
data_rows_param = "dataRowIds"
1233+
data_rows_param = "dataRowIdentifiers"
12121234
query_str = """mutation %sPyApi(
12131235
$%s: Int!
12141236
$%s: ID!
1215-
$%s: [ID!]
1237+
$%s: QueuePriorityUpdateDataRowIdentifiersInput
12161238
) {
12171239
project(where: { id: $%s }) {
12181240
%s(
1219-
data: { priority: $%s, dataRowIds: $%s }
1241+
data: { priority: $%s, dataRowIdentifiers: $%s }
12201242
) {
12211243
taskId
12221244
}
@@ -1228,7 +1250,10 @@ def update_data_row_labeling_priority(
12281250
query_str, {
12291251
priority_param: priority,
12301252
project_param: self.uid,
1231-
data_rows_param: data_rows
1253+
data_rows_param: {
1254+
"ids": [id for id in data_rows],
1255+
"idType": data_rows._id_type,
1256+
},
12321257
})["project"][method]
12331258

12341259
task_id = res['taskId']

tests/integration/conftest.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,18 @@ def consensus_project_with_batch(consensus_project, initial_dataset, rand_gen,
173173
project = consensus_project
174174
dataset = initial_dataset
175175

176-
task = dataset.create_data_rows([{DataRow.row_data: image_url}] * 3)
176+
data_rows = []
177+
for _ in range(3):
178+
data_rows.append({
179+
DataRow.row_data: image_url,
180+
DataRow.global_key: str(uuid.uuid4())
181+
})
182+
task = dataset.create_data_rows(data_rows)
177183
task.wait_till_done()
178184
assert task.status == "COMPLETE"
179185

180186
data_rows = list(dataset.data_rows())
181187
assert len(data_rows) == 3
182-
183188
batch = project.create_batch(
184189
rand_gen(str),
185190
data_rows, # sample of data row objects

tests/integration/test_labeling_parameter_overrides.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22
from labelbox import DataRow
3+
from labelbox.schema.identifiables import GlobalKeys, UniqueIds
34

45

56
def test_labeling_parameter_overrides(consensus_project_with_batch):
@@ -49,8 +50,21 @@ def test_set_labeling_priority(consensus_project_with_batch):
4950

5051
data = [data_row.uid for data_row in data_rows]
5152
success = project.update_data_row_labeling_priority(data, 1)
53+
lo = list(project.labeling_parameter_overrides())
5254
assert success
55+
assert len(lo) == 3
56+
assert {o.priority for o in lo} == {1, 1, 1}
5357

54-
updated_overrides = list(project.labeling_parameter_overrides())
55-
assert len(updated_overrides) == 3
56-
assert {o.priority for o in updated_overrides} == {1, 1, 1}
58+
data = [data_row.uid for data_row in data_rows]
59+
success = project.update_data_row_labeling_priority(UniqueIds(data), 2)
60+
lo = list(project.labeling_parameter_overrides())
61+
assert success
62+
assert len(lo) == 3
63+
assert {o.priority for o in lo} == {2, 2, 2}
64+
65+
data = [data_row.global_key for data_row in data_rows]
66+
success = project.update_data_row_labeling_priority(GlobalKeys(data), 3)
67+
lo = list(project.labeling_parameter_overrides())
68+
assert success
69+
assert len(lo) == 3
70+
assert {o.priority for o in lo} == {3, 3, 3}

tests/unit/test_unit_identifiables.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,13 @@ def test_global_keys():
1313
identifiables = GlobalKeys(ids)
1414
assert [i for i in identifiables] == ids
1515
assert identifiables._id_type == "GKEY"
16+
17+
18+
def test_repr():
19+
ids = ["a", "b", "c"]
20+
identifiables = GlobalKeys(ids)
21+
assert repr(identifiables) == "GlobalKeys(['a', 'b', 'c'])"
22+
23+
ids = ["a", "b", "c"]
24+
identifiables = UniqueIds(ids)
25+
assert repr(identifiables) == "UniqueIds(['a', 'b', 'c'])"

0 commit comments

Comments
 (0)