Skip to content

Commit d38ac45

Browse files
authored
[PLT-1490] Removed data row ids list on some project methods and removed get queue_modes (#1852)
1 parent de9b3ad commit d38ac45

File tree

5 files changed

+33
-181
lines changed

5 files changed

+33
-181
lines changed

libs/labelbox/src/labelbox/schema/project.py

Lines changed: 23 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
Optional,
1414
Tuple,
1515
Union,
16-
overload,
16+
get_args,
1717
)
1818

1919
from lbox.exceptions import (
@@ -40,7 +40,11 @@
4040
from labelbox.schema.export_task import ExportTask
4141
from labelbox.schema.id_type import IdType
4242
from labelbox.schema.identifiable import DataRowIdentifier, GlobalKey, UniqueId
43-
from labelbox.schema.identifiables import DataRowIdentifiers, UniqueIds
43+
from labelbox.schema.identifiables import (
44+
DataRowIdentifiers,
45+
GlobalKeys,
46+
UniqueIds,
47+
)
4448
from labelbox.schema.labeling_service import (
4549
LabelingService,
4650
LabelingServiceStatus,
@@ -67,9 +71,7 @@
6771

6872

6973
DataRowPriority = int
70-
LabelingParameterOverrideInput = Tuple[
71-
Union[DataRow, DataRowIdentifier], DataRowPriority
72-
]
74+
LabelingParameterOverrideInput = Tuple[DataRowIdentifier, DataRowPriority]
7375

7476
logger = logging.getLogger(__name__)
7577
MAX_SYNC_BATCH_ROW_COUNT = 1_000
@@ -79,23 +81,18 @@ def validate_labeling_parameter_overrides(
7981
data: List[LabelingParameterOverrideInput],
8082
) -> None:
8183
for idx, row in enumerate(data):
82-
if len(row) < 2:
83-
raise TypeError(
84-
f"Data must be a list of tuples each containing two elements: a DataRow or a DataRowIdentifier and priority (int). Found {len(row)} items. Index: {idx}"
85-
)
8684
data_row_identifier = row[0]
8785
priority = row[1]
88-
valid_types = (Entity.DataRow, UniqueId, GlobalKey)
89-
if not isinstance(data_row_identifier, valid_types):
86+
if not isinstance(data_row_identifier, get_args(DataRowIdentifier)):
9087
raise TypeError(
91-
f"Data row identifier should be be of type DataRow, UniqueId or GlobalKey. Found {type(data_row_identifier)} for data_row_identifier {data_row_identifier}"
88+
f"Data row identifier should be of type DataRowIdentifier. Found {type(data_row_identifier)}."
89+
)
90+
if len(row) < 2:
91+
raise TypeError(
92+
f"Data must be a list of tuples each containing two elements: a DataRowIdentifier and priority (int). Found {len(row)} items. Index: {idx}"
9293
)
93-
9494
if not isinstance(priority, int):
95-
if isinstance(data_row_identifier, Entity.DataRow):
96-
id = data_row_identifier.uid
97-
else:
98-
id = data_row_identifier
95+
id = data_row_identifier.key
9996
raise TypeError(
10097
f"Priority must be an int. Found {type(priority)} for data_row_identifier {id}"
10198
)
@@ -1046,57 +1043,6 @@ def _create_batch_async(
10461043

10471044
return self.client.get_batch(self.uid, batch_id)
10481045

1049-
def _update_queue_mode(self, mode: "QueueMode") -> "QueueMode":
1050-
"""
1051-
Updates the queueing mode of this project.
1052-
1053-
Deprecation notice: This method is deprecated. Going forward, projects must
1054-
go through a migration to have the queue mode changed. Users should specify the
1055-
queue mode for a project during creation if a non-default mode is desired.
1056-
1057-
For more information, visit https://docs.labelbox.com/reference/migrating-to-workflows#upcoming-changes
1058-
1059-
Args:
1060-
mode: the specified queue mode
1061-
1062-
Returns: the updated queueing mode of this project
1063-
1064-
"""
1065-
1066-
logger.warning(
1067-
"Updating the queue_mode for a project will soon no longer be supported."
1068-
)
1069-
1070-
if self.queue_mode == mode:
1071-
return mode
1072-
1073-
if mode == QueueMode.Batch:
1074-
status = "ENABLED"
1075-
elif mode == QueueMode.Dataset:
1076-
status = "DISABLED"
1077-
else:
1078-
raise ValueError(
1079-
"Must provide either `BATCH` or `DATASET` as a mode"
1080-
)
1081-
1082-
query_str = (
1083-
"""mutation %s($projectId: ID!, $status: TagSetStatusInput!) {
1084-
project(where: {id: $projectId}) {
1085-
setTagSetStatus(input: {tagSetStatus: $status}) {
1086-
tagSetStatus
1087-
}
1088-
}
1089-
}
1090-
"""
1091-
% "setTagSetStatusPyApi"
1092-
)
1093-
1094-
self.client.execute(
1095-
query_str, {"projectId": self.uid, "status": status}
1096-
)
1097-
1098-
return mode
1099-
11001046
def get_label_count(self) -> int:
11011047
"""
11021048
Returns: the total number of labels in this project.
@@ -1111,46 +1057,6 @@ def get_label_count(self) -> int:
11111057
res = self.client.execute(query_str, {"projectId": self.uid})
11121058
return res["project"]["labelCount"]
11131059

1114-
def get_queue_mode(self) -> "QueueMode":
1115-
"""
1116-
Provides the queue mode used for this project.
1117-
1118-
Deprecation notice: This method is deprecated and will be removed in
1119-
a future version. To obtain the queue mode of a project, simply refer
1120-
to the queue_mode attribute of a Project.
1121-
1122-
For more information, visit https://docs.labelbox.com/reference/migrating-to-workflows#upcoming-changes
1123-
1124-
Returns: the QueueMode for this project
1125-
1126-
"""
1127-
1128-
logger.warning(
1129-
"Obtaining the queue_mode for a project through this method will soon"
1130-
" no longer be supported."
1131-
)
1132-
1133-
query_str = (
1134-
"""query %s($projectId: ID!) {
1135-
project(where: {id: $projectId}) {
1136-
tagSetStatus
1137-
}
1138-
}
1139-
"""
1140-
% "GetTagSetStatusPyApi"
1141-
)
1142-
1143-
status = self.client.execute(query_str, {"projectId": self.uid})[
1144-
"project"
1145-
]["tagSetStatus"]
1146-
1147-
if status == "ENABLED":
1148-
return QueueMode.Batch
1149-
elif status == "DISABLED":
1150-
return QueueMode.Dataset
1151-
else:
1152-
raise ValueError("Status not known")
1153-
11541060
def add_model_config(self, model_config_id: str) -> str:
11551061
"""Adds a model config to this project.
11561062
@@ -1243,18 +1149,13 @@ def set_labeling_parameter_overrides(
12431149
See information on priority here:
12441150
https://docs.labelbox.com/en/configure-editor/queue-system#reservation-system
12451151
1246-
>>> project.set_labeling_parameter_overrides([
1247-
>>> (data_row_id1, 2), (data_row_id2, 1)])
1248-
or
12491152
>>> project.set_labeling_parameter_overrides([
12501153
>>> (data_row_gk1, 2), (data_row_gk2, 1)])
12511154
12521155
Args:
12531156
data (iterable): An iterable of tuples. Each tuple must contain
1254-
either (DataRow, DataRowPriority<int>)
1255-
or (DataRowIdentifier, priority<int>) for the new override.
1157+
(DataRowIdentifier, priority<int>) for the new override.
12561158
DataRowIdentifier is an object representing a data row id or a global key. A DataIdentifier object can be a UniqueIds or GlobalKeys class.
1257-
NOTE - passing whole DatRow is deprecated. Please use a DataRowIdentifier instead.
12581159
12591160
Priority:
12601161
* Data will be labeled in priority order.
@@ -1283,43 +1184,18 @@ def set_labeling_parameter_overrides(
12831184

12841185
data_rows_with_identifiers = ""
12851186
for data_row, priority in data:
1286-
if isinstance(data_row, DataRow):
1287-
data_rows_with_identifiers += f'{{dataRowIdentifier: {{id: "{data_row.uid}", idType: {IdType.DataRowId}}}, priority: {priority}}},'
1288-
elif isinstance(data_row, UniqueId) or isinstance(
1289-
data_row, GlobalKey
1290-
):
1291-
data_rows_with_identifiers += f'{{dataRowIdentifier: {{id: "{data_row.key}", idType: {data_row.id_type}}}, priority: {priority}}},'
1292-
else:
1293-
raise TypeError(
1294-
f"Data row identifier should be be of type DataRow or Data Row Identifier. Found {type(data_row)}."
1295-
)
1187+
data_rows_with_identifiers += f'{{dataRowIdentifier: {{id: "{data_row.key}", idType: {data_row.id_type}}}, priority: {priority}}},'
12961188

12971189
query_str = template.substitute(
12981190
dataWithDataRowIdentifiers=data_rows_with_identifiers
12991191
)
13001192
res = self.client.execute(query_str, {"projectId": self.uid})
13011193
return res["project"]["setLabelingParameterOverrides"]["success"]
13021194

1303-
@overload
13041195
def update_data_row_labeling_priority(
13051196
self,
13061197
data_rows: DataRowIdentifiers,
13071198
priority: int,
1308-
) -> bool:
1309-
pass
1310-
1311-
@overload
1312-
def update_data_row_labeling_priority(
1313-
self,
1314-
data_rows: List[str],
1315-
priority: int,
1316-
) -> bool:
1317-
pass
1318-
1319-
def update_data_row_labeling_priority(
1320-
self,
1321-
data_rows,
1322-
priority: int,
13231199
) -> bool:
13241200
"""
13251201
Updates labeling parameter overrides to this project in bulk. This method allows up to 1 million data rows to be
@@ -1329,16 +1205,16 @@ def update_data_row_labeling_priority(
13291205
https://docs.labelbox.com/en/configure-editor/queue-system#reservation-system
13301206
13311207
Args:
1332-
data_rows: a list of data row ids to update priorities for. This can be a list of strings or a DataRowIdentifiers object
1208+
data_rows: data row identifiers object to update priorities.
13331209
DataRowIdentifier objects are lists of ids or global keys. A DataIdentifier object can be a UniqueIds or GlobalKeys class.
13341210
priority (int): Priority for the new override. See above for more information.
13351211
13361212
Returns:
13371213
bool, indicates if the operation was a success.
13381214
"""
13391215

1340-
if isinstance(data_rows, list):
1341-
data_rows = UniqueIds(data_rows)
1216+
if not isinstance(data_rows, get_args(DataRowIdentifiers)):
1217+
raise TypeError("data_rows must be a DataRowIdentifiers object")
13421218

13431219
method = "createQueuePriorityUpdateTask"
13441220
priority_param = "priority"
@@ -1481,34 +1357,25 @@ def task_queues(self) -> List[TaskQueue]:
14811357
for field_values in task_queue_values
14821358
]
14831359

1484-
@overload
14851360
def move_data_rows_to_task_queue(
14861361
self, data_row_ids: DataRowIdentifiers, task_queue_id: str
14871362
):
1488-
pass
1489-
1490-
@overload
1491-
def move_data_rows_to_task_queue(
1492-
self, data_row_ids: List[str], task_queue_id: str
1493-
):
1494-
pass
1495-
1496-
def move_data_rows_to_task_queue(self, data_row_ids, task_queue_id: str):
14971363
"""
14981364
14991365
Moves data rows to the specified task queue.
15001366
15011367
Args:
1502-
data_row_ids: a list of data row ids to be moved. This can be a list of strings or a DataRowIdentifiers object
1368+
data_row_ids: a list of data row ids to be moved. This should be a DataRowIdentifiers object
15031369
DataRowIdentifier objects are lists of ids or global keys. A DataIdentifier object can be a UniqueIds or GlobalKeys class.
15041370
task_queue_id: the task queue id to be moved to, or None to specify the "Done" queue
15051371
15061372
Returns:
15071373
None if successful, or a raised error on failure
15081374
15091375
"""
1510-
if isinstance(data_row_ids, list):
1511-
data_row_ids = UniqueIds(data_row_ids)
1376+
1377+
if not isinstance(data_row_ids, get_args(DataRowIdentifiers)):
1378+
raise TypeError("data_rows must be a DataRowIdentifiers object")
15121379

15131380
method = "createBulkAddRowsToQueueTask"
15141381
query_str = (

libs/labelbox/tests/data/export/streamable/test_export_project_streamable.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from labelbox import Project, Dataset
1010
from labelbox.schema.data_row import DataRow
1111
from labelbox.schema.label import Label
12+
from labelbox import UniqueIds
1213

1314
IMAGE_URL = "https://storage.googleapis.com/lb-artifacts-testing-public/sdk_integration_test/potato.jpeg"
1415

@@ -128,7 +129,9 @@ def test_with_date_filters(
128129
review_queue = next(
129130
tq for tq in task_queues if tq.queue_type == "MANUAL_REVIEW_QUEUE"
130131
)
131-
project.move_data_rows_to_task_queue([data_row.uid], review_queue.uid)
132+
project.move_data_rows_to_task_queue(
133+
UniqueIds([data_row.uid]), review_queue.uid
134+
)
132135
export_task = project_export(
133136
project, task_name, filters=filters, params=params
134137
)

libs/labelbox/tests/integration/test_labeling_parameter_overrides.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_labeling_parameter_overrides(consensus_project_with_batch):
2323
data_rows[2].uid,
2424
}
2525

26-
data = [(data_rows[0], 4, 2), (data_rows[1], 3)]
26+
data = [(UniqueId(data_rows[0].uid), 4, 2), (UniqueId(data_rows[1].uid), 3)]
2727
success = project.set_labeling_parameter_overrides(data)
2828
assert success
2929

@@ -60,7 +60,7 @@ def test_labeling_parameter_overrides(consensus_project_with_batch):
6060
assert {o.priority for o in updated_overrides} == {2, 3, 4}
6161

6262
with pytest.raises(TypeError) as exc_info:
63-
data = [(data_rows[2], "a_string", 3)]
63+
data = [(UniqueId(data_rows[2].uid), "a_string", 3)]
6464
project.set_labeling_parameter_overrides(data)
6565
assert (
6666
str(exc_info.value)
@@ -72,7 +72,7 @@ def test_labeling_parameter_overrides(consensus_project_with_batch):
7272
project.set_labeling_parameter_overrides(data)
7373
assert (
7474
str(exc_info.value)
75-
== f"Data row identifier should be be of type DataRow, UniqueId or GlobalKey. Found <class 'str'> for data_row_identifier {data_rows[2].uid}"
75+
== "Data row identifier should be of type DataRowIdentifier. Found <class 'str'>."
7676
)
7777

7878

@@ -85,13 +85,6 @@ def test_set_labeling_priority(consensus_project_with_batch):
8585
assert len(init_labeling_parameter_overrides) == 3
8686
assert {o.priority for o in init_labeling_parameter_overrides} == {5, 5, 5}
8787

88-
data = [data_row.uid for data_row in data_rows]
89-
success = project.update_data_row_labeling_priority(data, 1)
90-
lo = list(project.labeling_parameter_overrides())
91-
assert success
92-
assert len(lo) == 3
93-
assert {o.priority for o in lo} == {1, 1, 1}
94-
9588
data = [data_row.uid for data_row in data_rows]
9689
success = project.update_data_row_labeling_priority(UniqueIds(data), 2)
9790
lo = list(project.labeling_parameter_overrides())

libs/labelbox/tests/integration/test_task_queue.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ def test_move_to_task(configured_batch_project_with_label):
6868
review_queue = next(
6969
tq for tq in task_queues if tq.queue_type == "MANUAL_REVIEW_QUEUE"
7070
)
71-
project.move_data_rows_to_task_queue([data_row.uid], review_queue.uid)
71+
project.move_data_rows_to_task_queue(
72+
UniqueIds([data_row.uid]), review_queue.uid
73+
)
7274
_validate_moved(project, "MANUAL_REVIEW_QUEUE", 1)
7375

7476
review_queue = next(

libs/labelbox/tests/unit/test_unit_project_validate_labeling_parameter_overrides.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,6 @@
66
from labelbox.schema.project import validate_labeling_parameter_overrides
77

88

9-
def test_validate_labeling_parameter_overrides_valid_data():
10-
mock_data_row = MagicMock(spec=DataRow)
11-
mock_data_row.uid = "abc"
12-
data = [(mock_data_row, 1), (UniqueId("efg"), 2), (GlobalKey("hij"), 3)]
13-
validate_labeling_parameter_overrides(data)
14-
15-
16-
def test_validate_labeling_parameter_overrides_invalid_data():
17-
data = [("abc", 1), (UniqueId("efg"), 2), (GlobalKey("hij"), 3)]
18-
with pytest.raises(TypeError):
19-
validate_labeling_parameter_overrides(data)
20-
21-
229
def test_validate_labeling_parameter_overrides_invalid_priority():
2310
mock_data_row = MagicMock(spec=DataRow)
2411
mock_data_row.uid = "abc"

0 commit comments

Comments
 (0)