diff --git a/src/label_studio_sdk/label_interface/control_tags.py b/src/label_studio_sdk/label_interface/control_tags.py index 4d03ffd1..330e9df2 100644 --- a/src/label_studio_sdk/label_interface/control_tags.py +++ b/src/label_studio_sdk/label_interface/control_tags.py @@ -270,11 +270,11 @@ def find_object_by_name(self, name: str) -> Optional[ObjectTag]: def _validate_labels(self, labels): """Check that labels is a subset of self.labels, used for - example when you're validate the annotaion or prediction to + example when you're validate the annotation or prediction to make sure there no undefined labels used. """ - if not self.labels: + if not self.labels or not labels: return True return set(labels).issubset(set(self.labels)) @@ -424,7 +424,7 @@ def _label_with_labels( ) kwargs[self._label_attr_name] = label - + return self._label_simple(to_name=to_name, **kwargs) def label( @@ -455,7 +455,7 @@ def label( Region A new Region object with the specified label applied. """ - if hasattr(self, "_label_attr_name"): + if hasattr(self, "_label_attr_name") and label is not None: return self._label_with_labels( label=label, to_name=to_name, *args, **kwargs ) diff --git a/src/label_studio_sdk/label_interface/interface.py b/src/label_studio_sdk/label_interface/interface.py index 571747e2..a37d3935 100644 --- a/src/label_studio_sdk/label_interface/interface.py +++ b/src/label_studio_sdk/label_interface/interface.py @@ -320,7 +320,7 @@ def create_regions(self, data: Dict[str, Union[str, Dict, List[str], List[Dict]] # 1. we should allow control.label to process custom payload outside of those strictly containing "label" # 2. we should be less open regarding the payload type and defining the strict typing elsewhere, # but likely that requires rewriting of how ControlTag.label() is working now - if isinstance(payload, str): + if isinstance(payload, (str, int, float)): payload = {'label': payload} elif isinstance(payload, list): if len(payload) > 0: @@ -331,6 +331,7 @@ def create_regions(self, data: Dict[str, Union[str, Dict, List[str], List[Dict]] if isinstance(payload, Dict): payload = [payload] + for item in payload: regions.append(control.label(**item))