Skip to content

Commit d47e638

Browse files
authored
Merge pull request #337 from Labelbox/DIAG-982
update to make the ability to separate between label and value and up…
2 parents d7e96ae + 5f10b66 commit d47e638

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

labelbox/schema/ontology.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,19 @@ class Option:
4040
options: (list)
4141
"""
4242
value: Union[str, int]
43+
label: Optional[Union[str, int]] = None
4344
schema_id: Optional[str] = None
4445
feature_schema_id: Optional[FeatureSchemaId] = None
4546
options: List["Classification"] = field(default_factory=list)
4647

47-
@property
48-
def label(self):
49-
return self.value
48+
def __post_init__(self):
49+
if self.label is None:
50+
self.label = self.value
5051

5152
@classmethod
5253
def from_dict(cls, dictionary: Dict[str, Any]):
5354
return cls(value=dictionary["value"],
55+
label=dictionary["label"],
5456
schema_id=dictionary.get("schemaNodeId", None),
5557
feature_schema_id=dictionary.get("featureSchemaId", None),
5658
options=[

tests/integration/test_ontology.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@
125125
"schemaNodeId": None,
126126
"featureSchemaId": None,
127127
"label": "yes",
128-
"value": "yes",
128+
"value": "definitely yes",
129129
"options": []
130130
}, {
131131
"schemaNodeId": None,
132132
"featureSchemaId": None,
133133
"label": "no",
134-
"value": "no",
134+
"value": "definitely not",
135135
"options": []
136136
}]
137137
}]
@@ -152,12 +152,22 @@ def test_create_classification(class_type) -> None:
152152

153153
@pytest.mark.parametrize("value, expected_value, typing",
154154
[(3, 3, int), ("string", "string", str)])
155-
def test_create_option(value, expected_value, typing) -> None:
155+
def test_create_option_with_value(value, expected_value, typing) -> None:
156156
o = Option(value=value)
157157
assert (o.value == expected_value)
158158
assert (o.value == o.label)
159159

160160

161+
@pytest.mark.parametrize("value, label, expected_value, typing",
162+
[(3, 2, 3, int),
163+
("string", "another string", "string", str)])
164+
def test_create_option_with_value_and_label(value, label, expected_value,
165+
typing) -> None:
166+
o = Option(value=value, label=label)
167+
assert (o.value == expected_value)
168+
assert o.value != o.label
169+
170+
161171
def test_create_empty_ontology() -> None:
162172
o = OntologyBuilder()
163173
assert (o.tools == [])

0 commit comments

Comments
 (0)