From b2aa12391cc6085b38f3090e519e6affc51ca331 Mon Sep 17 00:00:00 2001 From: Brent Gracey Date: Thu, 12 Aug 2021 13:33:06 +0100 Subject: [PATCH] Fixed import issue for complex/simple polygons --- darwin/__init__.py | 2 +- darwin/dataset/remote_dataset.py | 7 +++++-- darwin/importer/importer.py | 22 +++++++++++----------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/darwin/__init__.py b/darwin/__init__.py index 50401d608..00d6d61a2 100644 --- a/darwin/__init__.py +++ b/darwin/__init__.py @@ -4,4 +4,4 @@ from .client import Client # noqa from .team import Team # noqa -__version__ = "0.6.3" +__version__ = "0.6.4" diff --git a/darwin/dataset/remote_dataset.py b/darwin/dataset/remote_dataset.py index 376304f1c..52e962da1 100644 --- a/darwin/dataset/remote_dataset.py +++ b/darwin/dataset/remote_dataset.py @@ -383,14 +383,17 @@ def add_annotation_class(self, annotation_class): # Waiting for a better api for setting classes # in the meantime this will do all_classes = self.fetch_remote_classes(True) + annotation_class_type = (annotation_class.annotation_internal_type or annotation_class.annotation_type) match = [ cls for cls in all_classes if cls["name"] == annotation_class.name - and annotation_class.annotation_internal_type in cls["annotation_types"] + and annotation_class_type in cls["annotation_types"] ] if not match: - raise ValueError(f"Unknown annotation class {annotation_class.name}, id: {annotation_class.id}") + # We do not expect to reach here; as pervious logic divides annotation classes in imports + # between `in team` and `new to platform` + raise ValueError(f"Annotation class name: `{annotation_class.name}`, type: `{annotation_class_type}`; does not exist in Team.") datasets = match[0]["datasets"] # check that we are not already part of the dataset diff --git a/darwin/importer/importer.py b/darwin/importer/importer.py index 9a05867e9..481bf2e41 100644 --- a/darwin/importer/importer.py +++ b/darwin/importer/importer.py @@ -75,26 +75,26 @@ def get_remote_files(dataset, filenames): return remote_files -def _resolve_annotation_classes(annotation_classes: List[dt.AnnotationClass], classes_in_dataset, classes_in_team): - local_classes_not_in_dataset = set() - local_classes_not_in_team = set() +def _resolve_annotation_classes(local_annotation_classes: List[dt.AnnotationClass], classes_in_dataset, classes_in_team): + local_classes_not_in_dataset: set[dt.AnnotationClass] = set() + local_classes_not_in_team: set[dt.AnnotationClass] = set() - for cls in annotation_classes: - annotation_type = cls.annotation_internal_type or cls.annotation_type + for local_cls in local_annotation_classes: + local_annotation_type = local_cls.annotation_internal_type or local_cls.annotation_type # Only add the new class if it doesn't exist remotely already - if annotation_type in classes_in_dataset and cls.name in classes_in_dataset[annotation_type]: + if local_annotation_type in classes_in_dataset and local_cls.name in classes_in_dataset[local_annotation_type]: continue # Only add the new class if it's not included in the list of the missing classes already - if cls.name in [missing_class.name for missing_class in local_classes_not_in_dataset]: + if local_cls.name in [missing_class.name for missing_class in local_classes_not_in_dataset]: continue - if cls.name in [missing_class.name for missing_class in local_classes_not_in_team]: + if local_cls.name in [missing_class.name for missing_class in local_classes_not_in_team]: continue - if annotation_type in classes_in_team and cls.name in classes_in_team[annotation_type]: - local_classes_not_in_dataset.add(cls) + if local_annotation_type in classes_in_team and local_cls.name in classes_in_team[local_annotation_type]: + local_classes_not_in_dataset.add(local_cls) else: - local_classes_not_in_team.add(cls) + local_classes_not_in_team.add(local_cls) return local_classes_not_in_dataset, local_classes_not_in_team