Skip to content

Commit c0d5064

Browse files
authored
Merge pull request #560 from Labelbox/develop
[3.20.1]
2 parents 838fe1c + d2111e2 commit c0d5064

File tree

5 files changed

+24
-26
lines changed

5 files changed

+24
-26
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
# Version 3.20.1 (2022-05-02)
4+
## Updated
5+
* Ontology Classification `scope` field is only set for top level classifications
6+
37
# Version 3.20.0 (2022-04-27)
48
## Added
59
* Batches in a project can be retrieved with `project.batches()`

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ RUN apt install -y libsm6 \
77
ffmpeg \
88
libfontconfig1 \
99
libxrender1 \
10-
libgl1-mesa-glx
10+
libgl1-mesa-glx \
11+
libgeos-dev
1112

1213
WORKDIR /usr/src/labelbox
1314
COPY requirements.txt /usr/src/labelbox

labelbox/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name = "labelbox"
2-
__version__ = "3.20.0"
2+
__version__ = "3.20.1"
33

44
import sys
55
import warnings

labelbox/schema/ontology.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def asdict(self) -> Dict[str, Any]:
6969
"featureSchemaId": self.feature_schema_id,
7070
"label": self.label,
7171
"value": self.value,
72-
"options": [o.asdict() for o in self.options]
72+
"options": [o.asdict(is_subclass=True) for o in self.options]
7373
}
7474

7575
def add_option(self, option: 'Classification') -> None:
@@ -159,29 +159,25 @@ def from_dict(cls, dictionary: Dict[str, Any]) -> Dict[str, Any]:
159159
feature_schema_id=dictionary.get("featureSchemaId", None),
160160
scope=cls.Scope(dictionary.get("scope", cls.Scope.GLOBAL)))
161161

162-
def asdict(self) -> Dict[str, Any]:
162+
def asdict(self, is_subclass: bool = False) -> Dict[str, Any]:
163163
if self.class_type in self._REQUIRES_OPTIONS \
164164
and len(self.options) < 1:
165165
raise InconsistentOntologyException(
166166
f"Classification '{self.instructions}' requires options.")
167-
return {
168-
"type":
169-
self.class_type.value,
170-
"instructions":
171-
self.instructions,
172-
"name":
173-
self.name,
174-
"required":
175-
self.required,
167+
classification = {
168+
"type": self.class_type.value,
169+
"instructions": self.instructions,
170+
"name": self.name,
171+
"required": self.required,
176172
"options": [o.asdict() for o in self.options],
177-
"schemaNodeId":
178-
self.schema_id,
179-
"featureSchemaId":
180-
self.feature_schema_id,
181-
"scope":
182-
self.scope.value
183-
if self.scope is not None else self.Scope.GLOBAL.value
173+
"schemaNodeId": self.schema_id,
174+
"featureSchemaId": self.feature_schema_id
184175
}
176+
if is_subclass:
177+
return classification
178+
classification[
179+
"scope"] = self.scope.value if self.scope is not None else self.Scope.GLOBAL.value
180+
return classification
185181

186182
def add_option(self, option: Option) -> None:
187183
if option.value in (o.value for o in self.options):
@@ -258,7 +254,9 @@ def asdict(self) -> Dict[str, Any]:
258254
"name": self.name,
259255
"required": self.required,
260256
"color": self.color,
261-
"classifications": [c.asdict() for c in self.classifications],
257+
"classifications": [
258+
c.asdict(is_subclass=True) for c in self.classifications
259+
],
262260
"schemaNodeId": self.schema_id,
263261
"featureSchemaId": self.feature_schema_id
264262
}

tests/unit/test_unit_ontology.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@
4646
"nested classification",
4747
"type":
4848
"radio",
49-
"scope":
50-
"global",
5149
"options": [{
5250
"schemaNodeId":
5351
None,
@@ -64,7 +62,6 @@
6462
"instructions": "nested nested text",
6563
"name": "nested nested text",
6664
"type": "text",
67-
"scope": "global",
6865
"options": []
6966
}]
7067
}, {
@@ -81,7 +78,6 @@
8178
"instructions": "nested text",
8279
"name": "nested text",
8380
"type": "text",
84-
"scope": "global",
8581
"options": []
8682
}]
8783
}, {
@@ -250,6 +246,5 @@ def test_option_add_option() -> None:
250246

251247

252248
def test_ontology_asdict() -> None:
253-
print(OntologyBuilder.from_dict(_SAMPLE_ONTOLOGY))
254249
assert OntologyBuilder.from_dict(
255250
_SAMPLE_ONTOLOGY).asdict() == _SAMPLE_ONTOLOGY

0 commit comments

Comments
 (0)