Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PLA-801][external] fetch_remote_files() is called with an old, V1 argument #809

Merged
merged 3 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions darwin/cli_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ def set_file_status(dataset_slug: str, status: str, files: List[str]) -> None:
dataset_identifier=dataset_slug
)
items: Iterator[DatasetItem] = dataset.fetch_remote_files(
{"filenames": ",".join(files)}
{"item_names": ",".join(files)}
)
if status == "archived":
dataset.archive(items)
Expand Down Expand Up @@ -1066,7 +1066,7 @@ def delete_files(
dataset: RemoteDataset = client.get_remote_dataset(
dataset_identifier=dataset_slug
)
items, items_2 = tee(dataset.fetch_remote_files({"filenames": files}))
items, items_2 = tee(dataset.fetch_remote_files({"item_names": files}))
if not skip_user_confirmation and not secure_continue_request():
console.print("Cancelled.")
return
Expand Down Expand Up @@ -1281,7 +1281,7 @@ def post_comment(
_error(f"unable to find dataset: {dataset_slug}")

items: List[DatasetItem] = list(
dataset.fetch_remote_files(filters={"filenames": [filename]})
dataset.fetch_remote_files(filters={"item_names": [filename]})
)

if len(items) == 0:
Expand Down
5 changes: 5 additions & 0 deletions darwin/dataset/remote_dataset_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ def fetch_remote_files(
post_sort: Dict[str, str] = {}

if filters:
# Backward compatibility with V1 filter parameter
if "filenames" in filters:
filters["item_names"] = filters["filenames"]
del filters["filenames"]

for list_type in [
"item_names",
"statuses",
Expand Down
26 changes: 14 additions & 12 deletions darwin/importer/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,9 @@ def _get_team_properties_annotation_lookup(client):
team_properties = client.get_team_properties()

# (property-name, annotation_class_id): FullProperty object
team_properties_annotation_lookup: Dict[Tuple[str, Optional[int]], FullProperty] = (
{}
)
team_properties_annotation_lookup: Dict[
Tuple[str, Optional[int]], FullProperty
] = {}
for prop in team_properties:
team_properties_annotation_lookup[(prop.name, prop.annotation_class_id)] = prop

Expand Down Expand Up @@ -395,9 +395,11 @@ def _import_properties(

# raise error if annotation-property not present in metadata
if (annotation_name, a_prop.name) not in metadata_cls_prop_lookup:

# check if they are present in team properties
if (a_prop.name, annotation_class_id) in team_properties_annotation_lookup:
if (
a_prop.name,
annotation_class_id,
) in team_properties_annotation_lookup:
# get team property
t_prop: FullProperty = team_properties_annotation_lookup[
(a_prop.name, annotation_class_id)
Expand All @@ -411,7 +413,7 @@ def _import_properties(
] = set()
continue

# get team property value
# get team property value
t_prop_val = None
for prop_val in t_prop.property_values or []:
if prop_val.value == a_prop.value:
Expand Down Expand Up @@ -921,9 +923,9 @@ def import_annotations( # noqa: C901

# Need to re parse the files since we didn't save the annotations in memory
for local_path in set(local_file.path for local_file in local_files): # noqa: C401
imported_files: Union[List[dt.AnnotationFile], dt.AnnotationFile, None] = (
importer(local_path)
)
imported_files: Union[
List[dt.AnnotationFile], dt.AnnotationFile, None
] = importer(local_path)
if imported_files is None:
parsed_files = []
elif not isinstance(imported_files, List):
Expand Down Expand Up @@ -1323,9 +1325,9 @@ def _import_annotations(
# Insert the default slot name if not available in the import source
annotation = _handle_slot_names(annotation, dataset.version, default_slot_name)

annotation_class_ids_map[(annotation_class.name, annotation_type)] = (
annotation_class_id
)
annotation_class_ids_map[
(annotation_class.name, annotation_type)
] = annotation_class_id
serial_obj = {
"annotation_class_id": annotation_class_id,
"data": data,
Expand Down
16 changes: 8 additions & 8 deletions tests/darwin/cli_functions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def test_calls_dataset_archive(
dataset_identifier=dataset_identifier
)
fetch_remote_files_mock.assert_called_once_with(
{"filenames": "one.jpg,two.jpg"}
{"item_names": "one.jpg,two.jpg"}
)
mock.assert_called_once_with(fetch_remote_files_mock.return_value)

Expand All @@ -291,7 +291,7 @@ def test_calls_dataset_clear(
dataset_identifier=dataset_identifier
)
fetch_remote_files_mock.assert_called_once_with(
{"filenames": "one.jpg,two.jpg"}
{"item_names": "one.jpg,two.jpg"}
)
mock.assert_called_once_with(fetch_remote_files_mock.return_value)

Expand All @@ -310,7 +310,7 @@ def test_calls_dataset_new(
dataset_identifier=dataset_identifier
)
fetch_remote_files_mock.assert_called_once_with(
{"filenames": "one.jpg,two.jpg"}
{"item_names": "one.jpg,two.jpg"}
)
mock.assert_called_once_with(fetch_remote_files_mock.return_value)

Expand All @@ -331,7 +331,7 @@ def test_calls_dataset_restore_archived(
dataset_identifier=dataset_identifier
)
fetch_remote_files_mock.assert_called_once_with(
{"filenames": "one.jpg,two.jpg"}
{"item_names": "one.jpg,two.jpg"}
)
mock.assert_called_once_with(fetch_remote_files_mock.return_value)

Expand All @@ -356,7 +356,7 @@ def test_bypasses_user_prompt_if_yes_flag_is_true(
dataset_identifier=dataset_identifier
)
fetch_remote_files_mock.assert_called_once_with(
{"filenames": ["one.jpg", "two.jpg"]}
{"item_names": ["one.jpg", "two.jpg"]}
)
mock.assert_called_once()

Expand All @@ -376,7 +376,7 @@ def test_deletes_items_if_user_accepts_prompt(
dataset_identifier=dataset_identifier
)
fetch_remote_files_mock.assert_called_once_with(
{"filenames": ["one.jpg", "two.jpg"]}
{"item_names": ["one.jpg", "two.jpg"]}
)
mock.assert_called_once()

Expand All @@ -396,7 +396,7 @@ def test_does_not_delete_items_if_user_refuses_prompt(
dataset_identifier=dataset_identifier
)
fetch_remote_files_mock.assert_called_once_with(
{"filenames": ["one.jpg", "two.jpg"]}
{"item_names": ["one.jpg", "two.jpg"]}
)
mock.assert_not_called()

Expand All @@ -422,7 +422,7 @@ def error_mock():
dataset_identifier=dataset_identifier
)
fetch_remote_files_mock.assert_called_once_with(
{"filenames": ["one.jpg", "two.jpg"]}
{"item_names": ["one.jpg", "two.jpg"]}
)
mock.assert_called_once()
exception.assert_called_once_with(1)
Loading