Skip to content

Commit b51baef

Browse files
authored
Merge pull request #709 from Labelbox/long/ac-554-filter
[AC-554] project.export_labels: supporting filtering by time in start/end args
2 parents a707912 + bb6274a commit b51baef

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Updated docs for deprecated methods `_update_queue_mode` and `get_queue_mode` in `Project`
88
* Use the `queue_mode` attribute in `Project` to get and set the queue mode instead
99
* For more information, visit https://docs.labelbox.com/reference/migrating-to-workflows#upcoming-changes
10+
* Updated `project.export_labels` to support filtering by start/end time formats "YYYY-MM-DD" and "YYYY-MM-DD hh:mm:ss"
1011
### Fixed
1112

1213
# Version 3.27.1 (2022-09-16)

labelbox/schema/project.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ def export_labels(self,
289289
Args:
290290
download (bool): Returns the url if False
291291
timeout_seconds (float): Max waiting time, in seconds.
292-
start (str): Earliest date for labels, formatted "YYYY-MM-DD"
293-
end (str): Latest date for labels, formatted "YYYY-MM-DD"
292+
start (str): Earliest date for labels, formatted "YYYY-MM-DD" or "YYYY-MM-DD hh:mm:ss"
293+
end (str): Latest date for labels, formatted "YYYY-MM-DD" or "YYYY-MM-DD hh:mm:ss"
294294
Returns:
295295
URL of the data file with this Project's labels. If the server didn't
296296
generate during the `timeout_seconds` period, None is returned.
@@ -312,11 +312,14 @@ def _string_from_dict(dictionary: dict, value_with_quotes=False) -> str:
312312
def _validate_datetime(string_date: str) -> bool:
313313
"""helper function validate that datetime is as follows: YYYY-MM-DD for the export"""
314314
if string_date:
315-
try:
316-
datetime.strptime(string_date, "%Y-%m-%d")
317-
except ValueError:
318-
raise ValueError(f"""Incorrect format for: {string_date}.
319-
Format must be \"YYYY-MM-DD\"""")
315+
for fmt in ("%Y-%m-%d", "%Y-%m-%d %H:%M:%S"):
316+
try:
317+
datetime.strptime(string_date, fmt)
318+
return True
319+
except ValueError:
320+
pass
321+
raise ValueError(f"""Incorrect format for: {string_date}.
322+
Format must be \"YYYY-MM-DD\" or \"YYYY-MM-DD hh:mm:ss\"""")
320323
return True
321324

322325
sleep_time = 2

tests/integration/test_export.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ def test_export_filtered_dates(client,
8787
filtered_export = project.export_labels(download=True, start="2020-01-01")
8888
assert len(filtered_export) == 1
8989

90+
filtered_export_with_time = project.export_labels(
91+
download=True, start="2020-01-01 00:00:01")
92+
assert len(filtered_export_with_time) == 1
93+
9094
empty_export = project.export_labels(download=True,
9195
start="2020-01-01",
9296
end="2020-01-02")
93-
assert len(empty_export) == 0
97+
assert len(empty_export) == 0

0 commit comments

Comments
 (0)