Skip to content

Commit 0d3f0ef

Browse files
author
Kevin Kim
committed
Modify status result enum
1 parent e8f4d22 commit 0d3f0ef

File tree

3 files changed

+27
-45
lines changed

3 files changed

+27
-45
lines changed

labelbox/client.py

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@
2020
from labelbox.orm.db_object import DbObject
2121
from labelbox.orm.model import Entity
2222
from labelbox.pagination import PaginatedCollection
23-
from labelbox.schema.data_row import DataRow
2423
from labelbox.schema.data_row_metadata import DataRowMetadataOntology
2524
from labelbox.schema.dataset import Dataset
26-
from labelbox.schema.enums import TaskResult
25+
from labelbox.schema.enums import CollectionJobStatus
2726
from labelbox.schema.iam_integration import IAMIntegration
2827
from labelbox.schema import role
2928
from labelbox.schema.labeling_frontend import LabelingFrontend
@@ -1071,11 +1070,11 @@ def _format_failed_rows(rows: Dict[str, str],
10711070
error_msg="Access denied to Data Row"))
10721071

10731072
if not errors:
1074-
status = TaskResult.SUCCESS.value
1073+
status = CollectionJobStatus.SUCCESS.value
10751074
elif errors and results:
1076-
status = TaskResult.PARTIAL_SUCCESS.value
1075+
status = CollectionJobStatus.PARTIAL_SUCCESS.value
10771076
else:
1078-
status = TaskResult.FAILURE.value
1077+
status = CollectionJobStatus.FAILURE.value
10791078

10801079
if errors:
10811080
logger.warning(
@@ -1128,13 +1127,6 @@ def get_data_row_ids_for_global_keys(
11281127
[{'global_key': 'asdf', 'error': 'Data Row not found'}]
11291128
"""
11301129

1131-
def _format_successful_rows(
1132-
rows: List[Dict[str, str]]) -> List[Dict[str, str]]:
1133-
return [{
1134-
'data_row_id': r['id'],
1135-
'global_key': r['globalKey']
1136-
} for r in rows]
1137-
11381130
def _format_failed_rows(rows: List[str],
11391131
error_msg: str) -> List[Dict[str, str]]:
11401132
return [{'global_key': r, 'error': error_msg} for r in rows]
@@ -1149,7 +1141,7 @@ def _format_failed_rows(rows: List[str],
11491141
# Query string for retrieving job status and result, if job is done
11501142
result_query_str = """query getDataRowsForGlobalKeysResultPyApi($jobId: ID!) {
11511143
dataRowsForGlobalKeysResult(jobId: {id: $jobId}) { data {
1152-
fetchedDataRows { id globalKey }
1144+
fetchedDataRows { id }
11531145
notFoundGlobalKeys
11541146
accessDeniedGlobalKeys
11551147
deletedDataRowGlobalKeys
@@ -1168,7 +1160,7 @@ def _format_failed_rows(rows: List[str],
11681160
if res["dataRowsForGlobalKeysResult"]['jobStatus'] == "COMPLETE":
11691161
data = res["dataRowsForGlobalKeysResult"]['data']
11701162
results, errors = [], []
1171-
results.extend(_format_successful_rows(data['fetchedDataRows']))
1163+
results.extend([row['id'] for row in data['fetchedDataRows']])
11721164
errors.extend(
11731165
_format_failed_rows(data['notFoundGlobalKeys'],
11741166
"Data Row not found"))
@@ -1179,11 +1171,11 @@ def _format_failed_rows(rows: List[str],
11791171
_format_failed_rows(data['deletedDataRowGlobalKeys'],
11801172
"Data Row deleted"))
11811173
if not errors:
1182-
status = TaskResult.SUCCESS.value
1174+
status = CollectionJobStatus.SUCCESS.value
11831175
elif errors and results:
1184-
status = TaskResult.PARTIAL_SUCCESS.value
1176+
status = CollectionJobStatus.PARTIAL_SUCCESS.value
11851177
else:
1186-
status = TaskResult.FAILURE.value
1178+
status = CollectionJobStatus.FAILURE.value
11871179

11881180
if errors:
11891181
logger.warning(
@@ -1235,13 +1227,9 @@ def get_data_rows_for_global_keys(
12351227

12361228
# Query for data row by data_row_id to ensure we get all fields populated in DataRow instances
12371229
data_rows = []
1238-
for data_row in job_result['results']:
1239-
try:
1240-
data_rows.append(self.get_data_row(data_row['data_row_id']))
1241-
except labelbox.exceptions.ResourceNotFoundError:
1242-
raise labelbox.exceptions.ResourceNotFoundError(
1243-
f"Failed to fetch Data Row for id {data_row['data_row_id']}. Please verify that DataRow is not deleted"
1244-
)
1230+
for data_row_id in job_result['results']:
1231+
# TODO: Need to optimize this to run over a collection of data_row_ids
1232+
data_rows.append(self.get_data_row(data_row_id))
12451233

12461234
job_result['results'] = data_rows
12471235

labelbox/schema/enums.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,18 @@ class AnnotationImportState(Enum):
4646
FINISHED = "FINISHED"
4747

4848

49-
class TaskResult(Enum):
50-
SUCCESS = "Success"
51-
PARTIAL_SUCCESS = "Partial Success"
52-
FAILURE = "Failure"
49+
class CollectionJobStatus(Enum):
50+
""" Status of an asynchronous job over a collection.
51+
52+
* - State
53+
- Description
54+
* - SUCCESS
55+
- Indicates job has successfully processed entire collection of data
56+
* - PARTIAL SUCCESS
57+
- Indicates some data in the collection has succeeded and other data have failed
58+
* - FAILURE
59+
- Indicates job has failed to process entire collection of data
60+
"""
61+
SUCCESS = "SUCCESS"
62+
PARTIAL_SUCCESS = "PARTIAL SUCCESS"
63+
FAILURE = "FAILURE"

labelbox/schema/task_result.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)