Skip to content

Commit 0e9f43f

Browse files
[PLT-1392] [PLT-1350] Remove SDK methods for exports v1 (#1800)
1 parent cc9d6af commit 0e9f43f

File tree

14 files changed

+0
-1210
lines changed

14 files changed

+0
-1210
lines changed

libs/labelbox/src/labelbox/schema/batch.py

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -87,59 +87,6 @@ def remove_queued_data_rows(self) -> None:
8787
},
8888
experimental=True)
8989

90-
def export_data_rows(self,
91-
timeout_seconds=120,
92-
include_metadata: bool = False) -> Generator:
93-
""" Returns a generator that produces all data rows that are currently
94-
in this batch.
95-
96-
Note: For efficiency, the data are cached for 30 minutes. Newly created data rows will not appear
97-
until the end of the cache period.
98-
99-
Args:
100-
timeout_seconds (float): Max waiting time, in seconds.
101-
include_metadata (bool): True to return related DataRow metadata
102-
Returns:
103-
Generator that yields DataRow objects belonging to this batch.
104-
Raises:
105-
LabelboxError: if the export fails or is unable to download within the specified time.
106-
"""
107-
warnings.warn(
108-
"You are currently utilizing exports v1 for this action, which will be deprecated after April 30th, 2024. We recommend transitioning to exports v2. To view export v2 details, visit our docs: https://docs.labelbox.com/reference/label-export",
109-
DeprecationWarning)
110-
111-
id_param = "batchId"
112-
metadata_param = "includeMetadataInput"
113-
query_str = """mutation GetBatchDataRowsExportUrlPyApi($%s: ID!, $%s: Boolean!)
114-
{exportBatchDataRows(data:{batchId: $%s , includeMetadataInput: $%s}) {downloadUrl createdAt status}}
115-
""" % (id_param, metadata_param, id_param, metadata_param)
116-
sleep_time = 2
117-
while True:
118-
res = self.client.execute(query_str, {
119-
id_param: self.uid,
120-
metadata_param: include_metadata
121-
})
122-
res = res["exportBatchDataRows"]
123-
if res["status"] == "COMPLETE":
124-
download_url = res["downloadUrl"]
125-
response = requests.get(download_url)
126-
response.raise_for_status()
127-
reader = parser.reader(StringIO(response.text))
128-
return (
129-
Entity.DataRow(self.client, result) for result in reader)
130-
elif res["status"] == "FAILED":
131-
raise LabelboxError("Data row export failed.")
132-
133-
timeout_seconds -= sleep_time
134-
if timeout_seconds <= 0:
135-
raise LabelboxError(
136-
f"Unable to export data rows within {timeout_seconds} seconds."
137-
)
138-
139-
logger.debug("Batch '%s' data row export, waiting for server...",
140-
self.uid)
141-
time.sleep(sleep_time)
142-
14390
def delete(self) -> None:
14491
""" Deletes the given batch.
14592

libs/labelbox/src/labelbox/schema/dataset.py

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -337,58 +337,6 @@ def data_row_for_external_id(self, external_id) -> "DataRow":
337337
external_id)
338338
return data_rows[0]
339339

340-
def export_data_rows(self,
341-
timeout_seconds=120,
342-
include_metadata: bool = False) -> Generator:
343-
""" Returns a generator that produces all data rows that are currently
344-
attached to this dataset.
345-
346-
Note: For efficiency, the data are cached for 30 minutes. Newly created data rows will not appear
347-
until the end of the cache period.
348-
349-
Args:
350-
timeout_seconds (float): Max waiting time, in seconds.
351-
include_metadata (bool): True to return related DataRow metadata
352-
Returns:
353-
Generator that yields DataRow objects belonging to this dataset.
354-
Raises:
355-
LabelboxError: if the export fails or is unable to download within the specified time.
356-
"""
357-
warnings.warn(
358-
"You are currently utilizing exports v1 for this action, which will be deprecated after April 30th, 2024. We recommend transitioning to exports v2. To view export v2 details, visit our docs: https://docs.labelbox.com/reference/label-export",
359-
DeprecationWarning)
360-
id_param = "datasetId"
361-
metadata_param = "includeMetadataInput"
362-
query_str = """mutation GetDatasetDataRowsExportUrlPyApi($%s: ID!, $%s: Boolean!)
363-
{exportDatasetDataRows(data:{datasetId: $%s , includeMetadataInput: $%s}) {downloadUrl createdAt status}}
364-
""" % (id_param, metadata_param, id_param, metadata_param)
365-
sleep_time = 2
366-
while True:
367-
res = self.client.execute(query_str, {
368-
id_param: self.uid,
369-
metadata_param: include_metadata
370-
})
371-
res = res["exportDatasetDataRows"]
372-
if res["status"] == "COMPLETE":
373-
download_url = res["downloadUrl"]
374-
response = requests.get(download_url)
375-
response.raise_for_status()
376-
reader = parser.reader(StringIO(response.text))
377-
return (
378-
Entity.DataRow(self.client, result) for result in reader)
379-
elif res["status"] == "FAILED":
380-
raise LabelboxError("Data row export failed.")
381-
382-
timeout_seconds -= sleep_time
383-
if timeout_seconds <= 0:
384-
raise LabelboxError(
385-
f"Unable to export data rows within {timeout_seconds} seconds."
386-
)
387-
388-
logger.debug("Dataset '%s' data row export, waiting for server...",
389-
self.uid)
390-
time.sleep(sleep_time)
391-
392340
def export(
393341
self,
394342
task_name: Optional[str] = None,

libs/labelbox/src/labelbox/schema/model_run.py

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -461,57 +461,6 @@ def get_config(self) -> Dict[str, Any]:
461461
experimental=True)
462462
return res["modelRun"]["trainingMetadata"]
463463

464-
@experimental
465-
def export_labels(
466-
self,
467-
download: bool = False,
468-
timeout_seconds: int = 600
469-
) -> Optional[Union[str, List[Dict[Any, Any]]]]:
470-
"""
471-
Experimental. To use, make sure client has enable_experimental=True.
472-
473-
Fetches Labels from the ModelRun
474-
475-
Args:
476-
download (bool): Returns the url if False
477-
Returns:
478-
URL of the data file with this ModelRun's labels.
479-
If download=True, this instead returns the contents as NDJSON format.
480-
If the server didn't generate during the `timeout_seconds` period,
481-
None is returned.
482-
"""
483-
warnings.warn(
484-
"You are currently utilizing exports v1 for this action, which will be deprecated after April 30th, 2024. We recommend transitioning to exports v2. To view export v2 details, visit our docs: https://docs.labelbox.com/reference/label-export",
485-
DeprecationWarning)
486-
sleep_time = 2
487-
query_str = """mutation exportModelRunAnnotationsPyApi($modelRunId: ID!) {
488-
exportModelRunAnnotations(data: {modelRunId: $modelRunId}) {
489-
downloadUrl createdAt status
490-
}
491-
}
492-
"""
493-
494-
while True:
495-
url = self.client.execute(
496-
query_str, {'modelRunId': self.uid},
497-
experimental=True)['exportModelRunAnnotations']['downloadUrl']
498-
499-
if url:
500-
if not download:
501-
return url
502-
else:
503-
response = requests.get(url)
504-
response.raise_for_status()
505-
return parser.loads(response.content)
506-
507-
timeout_seconds -= sleep_time
508-
if timeout_seconds <= 0:
509-
return None
510-
511-
logger.debug("ModelRun '%s' label export, waiting for server...",
512-
self.uid)
513-
time.sleep(sleep_time)
514-
515464
def export(self,
516465
task_name: Optional[str] = None,
517466
params: Optional[ModelRunExportParams] = None) -> ExportTask:

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

Lines changed: 0 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -313,157 +313,6 @@ def labels(self, datasets=None, order_by=None) -> PaginatedCollection:
313313
return PaginatedCollection(self.client, query_str, {id_param: self.uid},
314314
["project", "labels"], Label)
315315

316-
def export_queued_data_rows(
317-
self,
318-
timeout_seconds=120,
319-
include_metadata: bool = False) -> List[Dict[str, str]]:
320-
""" Returns all data rows that are currently enqueued for this project.
321-
322-
Args:
323-
timeout_seconds (float): Max waiting time, in seconds.
324-
include_metadata (bool): True to return related DataRow metadata
325-
Returns:
326-
Data row fields for all data rows in the queue as json
327-
Raises:
328-
LabelboxError: if the export fails or is unable to download within the specified time.
329-
"""
330-
warnings.warn(
331-
"You are currently utilizing exports v1 for this action, which will be deprecated after April 30th, 2024. We recommend transitioning to exports v2. To view export v2 details, visit our docs: https://docs.labelbox.com/reference/label-export",
332-
DeprecationWarning)
333-
id_param = "projectId"
334-
metadata_param = "includeMetadataInput"
335-
query_str = """mutation GetQueuedDataRowsExportUrlPyApi($%s: ID!, $%s: Boolean!)
336-
{exportQueuedDataRows(data:{projectId: $%s , includeMetadataInput: $%s}) {downloadUrl createdAt status} }
337-
""" % (id_param, metadata_param, id_param, metadata_param)
338-
sleep_time = 2
339-
start_time = time.time()
340-
while True:
341-
res = self.client.execute(query_str, {
342-
id_param: self.uid,
343-
metadata_param: include_metadata
344-
})
345-
res = res["exportQueuedDataRows"]
346-
if res["status"] == "COMPLETE":
347-
download_url = res["downloadUrl"]
348-
response = requests.get(download_url)
349-
response.raise_for_status()
350-
return parser.loads(response.text)
351-
elif res["status"] == "FAILED":
352-
raise LabelboxError("Data row export failed.")
353-
354-
current_time = time.time()
355-
if current_time - start_time > timeout_seconds:
356-
raise LabelboxError(
357-
f"Unable to export data rows within {timeout_seconds} seconds."
358-
)
359-
360-
logger.debug(
361-
"Project '%s' queued data row export, waiting for server...",
362-
self.uid)
363-
time.sleep(sleep_time)
364-
365-
def export_labels(self,
366-
download=False,
367-
timeout_seconds=1800,
368-
**kwargs) -> Optional[Union[str, List[Dict[Any, Any]]]]:
369-
""" Calls the server-side Label exporting that generates a JSON
370-
payload, and returns the URL to that payload.
371-
372-
Will only generate a new URL at a max frequency of 30 min.
373-
374-
Args:
375-
download (bool): Returns the url if False
376-
timeout_seconds (float): Max waiting time, in seconds.
377-
start (str): Earliest date for labels, formatted "YYYY-MM-DD" or "YYYY-MM-DD hh:mm:ss"
378-
end (str): Latest date for labels, formatted "YYYY-MM-DD" or "YYYY-MM-DD hh:mm:ss"
379-
last_activity_start (str): Will include all labels that have had any updates to
380-
data rows, issues, comments, metadata, or reviews since this timestamp.
381-
formatted "YYYY-MM-DD" or "YYYY-MM-DD hh:mm:ss"
382-
last_activity_end (str): Will include all labels that do not have any updates to
383-
data rows, issues, comments, metadata, or reviews after this timestamp.
384-
formatted "YYYY-MM-DD" or "YYYY-MM-DD hh:mm:ss"
385-
386-
Returns:
387-
URL of the data file with this Project's labels. If the server didn't
388-
generate during the `timeout_seconds` period, None is returned.
389-
"""
390-
warnings.warn(
391-
"You are currently utilizing exports v1 for this action, which will be deprecated after April 30th, 2024. We recommend transitioning to exports v2. To view export v2 details, visit our docs: https://docs.labelbox.com/reference/label-export",
392-
DeprecationWarning)
393-
394-
def _string_from_dict(dictionary: dict, value_with_quotes=False) -> str:
395-
"""Returns a concatenated string of the dictionary's keys and values
396-
397-
The string will be formatted as {key}: 'value' for each key. Value will be inclusive of
398-
quotations while key will not. This can be toggled with `value_with_quotes`"""
399-
400-
quote = "\"" if value_with_quotes else ""
401-
return ",".join([
402-
f"""{c}: {quote}{dictionary.get(c)}{quote}"""
403-
for c in dictionary
404-
if dictionary.get(c)
405-
])
406-
407-
sleep_time = 2
408-
id_param = "projectId"
409-
filter_param = ""
410-
filter_param_dict = {}
411-
412-
if "start" in kwargs or "end" in kwargs:
413-
created_at_dict = {
414-
"start": kwargs.get("start", ""),
415-
"end": kwargs.get("end", "")
416-
}
417-
[validate_datetime(date) for date in created_at_dict.values()]
418-
filter_param_dict["labelCreatedAt"] = "{%s}" % _string_from_dict(
419-
created_at_dict, value_with_quotes=True)
420-
421-
if "last_activity_start" in kwargs or "last_activity_end" in kwargs:
422-
last_activity_start = kwargs.get('last_activity_start')
423-
last_activity_end = kwargs.get('last_activity_end')
424-
425-
if last_activity_start:
426-
validate_datetime(str(last_activity_start))
427-
if last_activity_end:
428-
validate_datetime(str(last_activity_end))
429-
430-
filter_param_dict["lastActivityAt"] = "{%s}" % _string_from_dict(
431-
{
432-
"start": last_activity_start,
433-
"end": last_activity_end
434-
},
435-
value_with_quotes=True)
436-
437-
if filter_param_dict:
438-
filter_param = """, filters: {%s }""" % (_string_from_dict(
439-
filter_param_dict, value_with_quotes=False))
440-
441-
query_str = """mutation GetLabelExportUrlPyApi($%s: ID!)
442-
{exportLabels(data:{projectId: $%s%s}) {downloadUrl createdAt shouldPoll} }
443-
""" % (id_param, id_param, filter_param)
444-
445-
start_time = time.time()
446-
447-
while True:
448-
res = self.client.execute(query_str, {id_param: self.uid})
449-
res = res["exportLabels"]
450-
if not res["shouldPoll"] and res["downloadUrl"] is not None:
451-
url = res['downloadUrl']
452-
if not download:
453-
return url
454-
else:
455-
response = requests.get(url)
456-
response.raise_for_status()
457-
return response.json()
458-
459-
current_time = time.time()
460-
if current_time - start_time > timeout_seconds:
461-
return None
462-
463-
logger.debug("Project '%s' label export, waiting for server...",
464-
self.uid)
465-
time.sleep(sleep_time)
466-
467316
def export(
468317
self,
469318
task_name: Optional[str] = None,
@@ -1944,4 +1793,3 @@ class LabelingParameterOverride(DbObject):
19441793
"consensus average_benchmark_agreement last_activity_time")
19451794
LabelerPerformance.__doc__ = (
19461795
"Named tuple containing info about a labeler's performance.")
1947-

libs/labelbox/tests/data/annotation_types/test_collection.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ def create_data_rows(self, args):
4646
def wait_till_done(self):
4747
pass
4848

49-
def export_data_rows(self):
50-
for export in self.exports:
51-
yield export
52-
5349

5450
def test_generator(list_of_labels):
5551
generator = LabelGenerator([list_of_labels[0]])

libs/labelbox/tests/data/export/legacy/test_export_catalog.py

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

0 commit comments

Comments
 (0)