13
13
Optional ,
14
14
Tuple ,
15
15
Union ,
16
- overload ,
16
+ get_args ,
17
17
)
18
18
19
19
from lbox .exceptions import (
40
40
from labelbox .schema .export_task import ExportTask
41
41
from labelbox .schema .id_type import IdType
42
42
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
+ )
44
48
from labelbox .schema .labeling_service import (
45
49
LabelingService ,
46
50
LabelingServiceStatus ,
67
71
68
72
69
73
DataRowPriority = int
70
- LabelingParameterOverrideInput = Tuple [
71
- Union [DataRow , DataRowIdentifier ], DataRowPriority
72
- ]
74
+ LabelingParameterOverrideInput = Tuple [DataRowIdentifier , DataRowPriority ]
73
75
74
76
logger = logging .getLogger (__name__ )
75
77
MAX_SYNC_BATCH_ROW_COUNT = 1_000
@@ -79,23 +81,18 @@ def validate_labeling_parameter_overrides(
79
81
data : List [LabelingParameterOverrideInput ],
80
82
) -> None :
81
83
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
- )
86
84
data_row_identifier = row [0 ]
87
85
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 )):
90
87
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 } "
92
93
)
93
-
94
94
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
99
96
raise TypeError (
100
97
f"Priority must be an int. Found { type (priority )} for data_row_identifier { id } "
101
98
)
@@ -1048,57 +1045,6 @@ def _create_batch_async(
1048
1045
1049
1046
return self .client .get_batch (self .uid , batch_id )
1050
1047
1051
- def _update_queue_mode (self , mode : "QueueMode" ) -> "QueueMode" :
1052
- """
1053
- Updates the queueing mode of this project.
1054
-
1055
- Deprecation notice: This method is deprecated. Going forward, projects must
1056
- go through a migration to have the queue mode changed. Users should specify the
1057
- queue mode for a project during creation if a non-default mode is desired.
1058
-
1059
- For more information, visit https://docs.labelbox.com/reference/migrating-to-workflows#upcoming-changes
1060
-
1061
- Args:
1062
- mode: the specified queue mode
1063
-
1064
- Returns: the updated queueing mode of this project
1065
-
1066
- """
1067
-
1068
- logger .warning (
1069
- "Updating the queue_mode for a project will soon no longer be supported."
1070
- )
1071
-
1072
- if self .queue_mode == mode :
1073
- return mode
1074
-
1075
- if mode == QueueMode .Batch :
1076
- status = "ENABLED"
1077
- elif mode == QueueMode .Dataset :
1078
- status = "DISABLED"
1079
- else :
1080
- raise ValueError (
1081
- "Must provide either `BATCH` or `DATASET` as a mode"
1082
- )
1083
-
1084
- query_str = (
1085
- """mutation %s($projectId: ID!, $status: TagSetStatusInput!) {
1086
- project(where: {id: $projectId}) {
1087
- setTagSetStatus(input: {tagSetStatus: $status}) {
1088
- tagSetStatus
1089
- }
1090
- }
1091
- }
1092
- """
1093
- % "setTagSetStatusPyApi"
1094
- )
1095
-
1096
- self .client .execute (
1097
- query_str , {"projectId" : self .uid , "status" : status }
1098
- )
1099
-
1100
- return mode
1101
-
1102
1048
def get_label_count (self ) -> int :
1103
1049
"""
1104
1050
Returns: the total number of labels in this project.
@@ -1113,46 +1059,6 @@ def get_label_count(self) -> int:
1113
1059
res = self .client .execute (query_str , {"projectId" : self .uid })
1114
1060
return res ["project" ]["labelCount" ]
1115
1061
1116
- def get_queue_mode (self ) -> "QueueMode" :
1117
- """
1118
- Provides the queue mode used for this project.
1119
-
1120
- Deprecation notice: This method is deprecated and will be removed in
1121
- a future version. To obtain the queue mode of a project, simply refer
1122
- to the queue_mode attribute of a Project.
1123
-
1124
- For more information, visit https://docs.labelbox.com/reference/migrating-to-workflows#upcoming-changes
1125
-
1126
- Returns: the QueueMode for this project
1127
-
1128
- """
1129
-
1130
- logger .warning (
1131
- "Obtaining the queue_mode for a project through this method will soon"
1132
- " no longer be supported."
1133
- )
1134
-
1135
- query_str = (
1136
- """query %s($projectId: ID!) {
1137
- project(where: {id: $projectId}) {
1138
- tagSetStatus
1139
- }
1140
- }
1141
- """
1142
- % "GetTagSetStatusPyApi"
1143
- )
1144
-
1145
- status = self .client .execute (query_str , {"projectId" : self .uid })[
1146
- "project"
1147
- ]["tagSetStatus" ]
1148
-
1149
- if status == "ENABLED" :
1150
- return QueueMode .Batch
1151
- elif status == "DISABLED" :
1152
- return QueueMode .Dataset
1153
- else :
1154
- raise ValueError ("Status not known" )
1155
-
1156
1062
def add_model_config (self , model_config_id : str ) -> str :
1157
1063
"""Adds a model config to this project.
1158
1064
@@ -1245,18 +1151,13 @@ def set_labeling_parameter_overrides(
1245
1151
See information on priority here:
1246
1152
https://docs.labelbox.com/en/configure-editor/queue-system#reservation-system
1247
1153
1248
- >>> project.set_labeling_parameter_overrides([
1249
- >>> (data_row_id1, 2), (data_row_id2, 1)])
1250
- or
1251
1154
>>> project.set_labeling_parameter_overrides([
1252
1155
>>> (data_row_gk1, 2), (data_row_gk2, 1)])
1253
1156
1254
1157
Args:
1255
1158
data (iterable): An iterable of tuples. Each tuple must contain
1256
- either (DataRow, DataRowPriority<int>)
1257
- or (DataRowIdentifier, priority<int>) for the new override.
1159
+ (DataRowIdentifier, priority<int>) for the new override.
1258
1160
DataRowIdentifier is an object representing a data row id or a global key. A DataIdentifier object can be a UniqueIds or GlobalKeys class.
1259
- NOTE - passing whole DatRow is deprecated. Please use a DataRowIdentifier instead.
1260
1161
1261
1162
Priority:
1262
1163
* Data will be labeled in priority order.
@@ -1285,43 +1186,18 @@ def set_labeling_parameter_overrides(
1285
1186
1286
1187
data_rows_with_identifiers = ""
1287
1188
for data_row , priority in data :
1288
- if isinstance (data_row , DataRow ):
1289
- data_rows_with_identifiers += f'{{dataRowIdentifier: {{id: "{ data_row .uid } ", idType: { IdType .DataRowId } }}, priority: { priority } }},'
1290
- elif isinstance (data_row , UniqueId ) or isinstance (
1291
- data_row , GlobalKey
1292
- ):
1293
- data_rows_with_identifiers += f'{{dataRowIdentifier: {{id: "{ data_row .key } ", idType: { data_row .id_type } }}, priority: { priority } }},'
1294
- else :
1295
- raise TypeError (
1296
- f"Data row identifier should be be of type DataRow or Data Row Identifier. Found { type (data_row )} ."
1297
- )
1189
+ data_rows_with_identifiers += f'{{dataRowIdentifier: {{id: "{ data_row .key } ", idType: { data_row .id_type } }}, priority: { priority } }},'
1298
1190
1299
1191
query_str = template .substitute (
1300
1192
dataWithDataRowIdentifiers = data_rows_with_identifiers
1301
1193
)
1302
1194
res = self .client .execute (query_str , {"projectId" : self .uid })
1303
1195
return res ["project" ]["setLabelingParameterOverrides" ]["success" ]
1304
1196
1305
- @overload
1306
1197
def update_data_row_labeling_priority (
1307
1198
self ,
1308
1199
data_rows : DataRowIdentifiers ,
1309
1200
priority : int ,
1310
- ) -> bool :
1311
- pass
1312
-
1313
- @overload
1314
- def update_data_row_labeling_priority (
1315
- self ,
1316
- data_rows : List [str ],
1317
- priority : int ,
1318
- ) -> bool :
1319
- pass
1320
-
1321
- def update_data_row_labeling_priority (
1322
- self ,
1323
- data_rows ,
1324
- priority : int ,
1325
1201
) -> bool :
1326
1202
"""
1327
1203
Updates labeling parameter overrides to this project in bulk. This method allows up to 1 million data rows to be
@@ -1331,16 +1207,16 @@ def update_data_row_labeling_priority(
1331
1207
https://docs.labelbox.com/en/configure-editor/queue-system#reservation-system
1332
1208
1333
1209
Args:
1334
- data_rows: a list of data row ids to update priorities for. This can be a list of strings or a DataRowIdentifiers object
1210
+ data_rows: data row identifiers object to update priorities.
1335
1211
DataRowIdentifier objects are lists of ids or global keys. A DataIdentifier object can be a UniqueIds or GlobalKeys class.
1336
1212
priority (int): Priority for the new override. See above for more information.
1337
1213
1338
1214
Returns:
1339
1215
bool, indicates if the operation was a success.
1340
1216
"""
1341
1217
1342
- if isinstance (data_rows , list ):
1343
- data_rows = UniqueIds ( data_rows )
1218
+ if not isinstance (data_rows , get_args ( DataRowIdentifiers ) ):
1219
+ raise TypeError ( " data_rows must be a DataRowIdentifiers object" )
1344
1220
1345
1221
method = "createQueuePriorityUpdateTask"
1346
1222
priority_param = "priority"
@@ -1483,34 +1359,25 @@ def task_queues(self) -> List[TaskQueue]:
1483
1359
for field_values in task_queue_values
1484
1360
]
1485
1361
1486
- @overload
1487
1362
def move_data_rows_to_task_queue (
1488
1363
self , data_row_ids : DataRowIdentifiers , task_queue_id : str
1489
1364
):
1490
- pass
1491
-
1492
- @overload
1493
- def move_data_rows_to_task_queue (
1494
- self , data_row_ids : List [str ], task_queue_id : str
1495
- ):
1496
- pass
1497
-
1498
- def move_data_rows_to_task_queue (self , data_row_ids , task_queue_id : str ):
1499
1365
"""
1500
1366
1501
1367
Moves data rows to the specified task queue.
1502
1368
1503
1369
Args:
1504
- data_row_ids: a list of data row ids to be moved. This can be a list of strings or a DataRowIdentifiers object
1370
+ data_row_ids: a list of data row ids to be moved. This should be a DataRowIdentifiers object
1505
1371
DataRowIdentifier objects are lists of ids or global keys. A DataIdentifier object can be a UniqueIds or GlobalKeys class.
1506
1372
task_queue_id: the task queue id to be moved to, or None to specify the "Done" queue
1507
1373
1508
1374
Returns:
1509
1375
None if successful, or a raised error on failure
1510
1376
1511
1377
"""
1512
- if isinstance (data_row_ids , list ):
1513
- data_row_ids = UniqueIds (data_row_ids )
1378
+
1379
+ if not isinstance (data_row_ids , get_args (DataRowIdentifiers )):
1380
+ raise TypeError ("data_rows must be a DataRowIdentifiers object" )
1514
1381
1515
1382
method = "createBulkAddRowsToQueueTask"
1516
1383
query_str = (
0 commit comments