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
)
@@ -1046,57 +1043,6 @@ def _create_batch_async(
1046
1043
1047
1044
return self .client .get_batch (self .uid , batch_id )
1048
1045
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
-
1100
1046
def get_label_count (self ) -> int :
1101
1047
"""
1102
1048
Returns: the total number of labels in this project.
@@ -1111,46 +1057,6 @@ def get_label_count(self) -> int:
1111
1057
res = self .client .execute (query_str , {"projectId" : self .uid })
1112
1058
return res ["project" ]["labelCount" ]
1113
1059
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
-
1154
1060
def add_model_config (self , model_config_id : str ) -> str :
1155
1061
"""Adds a model config to this project.
1156
1062
@@ -1243,18 +1149,13 @@ def set_labeling_parameter_overrides(
1243
1149
See information on priority here:
1244
1150
https://docs.labelbox.com/en/configure-editor/queue-system#reservation-system
1245
1151
1246
- >>> project.set_labeling_parameter_overrides([
1247
- >>> (data_row_id1, 2), (data_row_id2, 1)])
1248
- or
1249
1152
>>> project.set_labeling_parameter_overrides([
1250
1153
>>> (data_row_gk1, 2), (data_row_gk2, 1)])
1251
1154
1252
1155
Args:
1253
1156
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.
1256
1158
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.
1258
1159
1259
1160
Priority:
1260
1161
* Data will be labeled in priority order.
@@ -1283,43 +1184,18 @@ def set_labeling_parameter_overrides(
1283
1184
1284
1185
data_rows_with_identifiers = ""
1285
1186
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 } }},'
1296
1188
1297
1189
query_str = template .substitute (
1298
1190
dataWithDataRowIdentifiers = data_rows_with_identifiers
1299
1191
)
1300
1192
res = self .client .execute (query_str , {"projectId" : self .uid })
1301
1193
return res ["project" ]["setLabelingParameterOverrides" ]["success" ]
1302
1194
1303
- @overload
1304
1195
def update_data_row_labeling_priority (
1305
1196
self ,
1306
1197
data_rows : DataRowIdentifiers ,
1307
1198
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 ,
1323
1199
) -> bool :
1324
1200
"""
1325
1201
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(
1329
1205
https://docs.labelbox.com/en/configure-editor/queue-system#reservation-system
1330
1206
1331
1207
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.
1333
1209
DataRowIdentifier objects are lists of ids or global keys. A DataIdentifier object can be a UniqueIds or GlobalKeys class.
1334
1210
priority (int): Priority for the new override. See above for more information.
1335
1211
1336
1212
Returns:
1337
1213
bool, indicates if the operation was a success.
1338
1214
"""
1339
1215
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" )
1342
1218
1343
1219
method = "createQueuePriorityUpdateTask"
1344
1220
priority_param = "priority"
@@ -1481,34 +1357,25 @@ def task_queues(self) -> List[TaskQueue]:
1481
1357
for field_values in task_queue_values
1482
1358
]
1483
1359
1484
- @overload
1485
1360
def move_data_rows_to_task_queue (
1486
1361
self , data_row_ids : DataRowIdentifiers , task_queue_id : str
1487
1362
):
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 ):
1497
1363
"""
1498
1364
1499
1365
Moves data rows to the specified task queue.
1500
1366
1501
1367
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
1503
1369
DataRowIdentifier objects are lists of ids or global keys. A DataIdentifier object can be a UniqueIds or GlobalKeys class.
1504
1370
task_queue_id: the task queue id to be moved to, or None to specify the "Done" queue
1505
1371
1506
1372
Returns:
1507
1373
None if successful, or a raised error on failure
1508
1374
1509
1375
"""
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" )
1512
1379
1513
1380
method = "createBulkAddRowsToQueueTask"
1514
1381
query_str = (
0 commit comments