Skip to content

Commit

Permalink
Fix singletons in labels
Browse files Browse the repository at this point in the history
  • Loading branch information
nik committed Oct 21, 2024
1 parent 99fd286 commit f293736
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/label_studio_sdk/label_interface/control_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
)
Expand Down
3 changes: 2 additions & 1 deletion src/label_studio_sdk/label_interface/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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))

Expand Down

0 comments on commit f293736

Please sign in to comment.