Skip to content

Commit 475af0e

Browse files
author
Matt Sokoloff
committed
LabelCollection -> LabelList
1 parent a4e2d0c commit 475af0e

File tree

5 files changed

+27
-27
lines changed

5 files changed

+27
-27
lines changed

labelbox/data/annotation_types/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@
2424

2525
from .label import Label
2626

27-
from .collection import LabelCollection
27+
from .collection import LabelList
2828
from .collection import LabelGenerator

labelbox/data/annotation_types/collection.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
logger = logging.getLogger(__name__)
1414

1515

16-
class LabelCollection:
16+
class LabelList:
1717
"""
1818
A container for interacting with a collection of labels.
1919
Less memory efficient than LabelGenerator but more performant and convenient to use.
@@ -24,16 +24,16 @@ def __init__(self, data: Iterable[Label]):
2424
self._data = data
2525
self._index = 0
2626

27-
def assign_schema_ids(
28-
self, ontology_builder: OntologyBuilder) -> "LabelCollection":
27+
def assign_schema_ids(self,
28+
ontology_builder: OntologyBuilder) -> "LabelList":
2929
"""
3030
Adds schema ids to all FeatureSchema objects in the Labels.
3131
This is necessary for MAL.
3232
3333
Args:
34-
ontology_builder: The ontology that matches the feature names assigned to objects in this LabelCollection
34+
ontology_builder: The ontology that matches the feature names assigned to objects in this LabelList
3535
Returns:
36-
LabelCollection. useful for chaining these modifying functions
36+
LabelList. useful for chaining these modifying functions
3737
"""
3838
for label in self._data:
3939
label.assign_schema_ids(ontology_builder)
@@ -42,7 +42,7 @@ def assign_schema_ids(
4242
def add_to_dataset(self,
4343
dataset: "Entity.Dataset",
4444
signer: Callable[[bytes], str],
45-
max_concurrency=20) -> "LabelCollection":
45+
max_concurrency=20) -> "LabelList":
4646
"""
4747
Creates data rows from each labels data object and attaches the data to the given dataset.
4848
Updates the label's data object to have the same external_id and uid as the data row.
@@ -55,7 +55,7 @@ def add_to_dataset(self,
5555
dataset: labelbox dataset object to add the new data row to
5656
signer: A function that accepts bytes and returns a signed url.
5757
Returns:
58-
LabelCollection with updated references to new data rows
58+
LabelList with updated references to new data rows
5959
"""
6060
self._ensure_unique_external_ids()
6161
self.add_url_to_data(signer, max_concurrency=max_concurrency)
@@ -73,9 +73,9 @@ def add_to_dataset(self,
7373
label.data.uid = data_row_lookup[label.data.external_id]
7474
return self
7575

76-
def add_url_to_masks(self, signer, max_concurrency=20) -> "LabelCollection":
76+
def add_url_to_masks(self, signer, max_concurrency=20) -> "LabelList":
7777
"""
78-
Creates signed urls for all masks in the LabelCollection.
78+
Creates signed urls for all masks in the LabelList.
7979
Multiple masks can reference the same RasterData mask so this makes sure we only upload that url once.
8080
Only uploads url if one doesn't already exist.
8181
@@ -84,15 +84,15 @@ def add_url_to_masks(self, signer, max_concurrency=20) -> "LabelCollection":
8484
max_concurrency: how many threads to use for uploading.
8585
Should be balanced to match the signing services capabilities.
8686
Returns:
87-
LabelCollection with updated references to the new mask urls
87+
LabelList with updated references to the new mask urls
8888
"""
8989
for row in self._apply_threaded(
9090
[label.add_url_to_masks for label in self._data], max_concurrency,
9191
signer):
9292
...
9393
return self
9494

95-
def add_url_to_data(self, signer, max_concurrency=20) -> "LabelCollection":
95+
def add_url_to_data(self, signer, max_concurrency=20) -> "LabelList":
9696
"""
9797
Creates signed urls for the data
9898
Only uploads url if one doesn't already exist.
@@ -102,7 +102,7 @@ def add_url_to_data(self, signer, max_concurrency=20) -> "LabelCollection":
102102
max_concurrency: how many threads to use for uploading.
103103
Should be balanced to match the signing services capabilities.
104104
Returns:
105-
LabelCollection with updated references to the new data urls
105+
LabelList with updated references to the new data urls
106106
"""
107107
for row in self._apply_threaded(
108108
[label.add_url_to_data for label in self._data], max_concurrency,
@@ -122,7 +122,7 @@ def _ensure_unique_external_ids(self) -> None:
122122
)
123123
external_ids.add(label.data.external_id)
124124

125-
def __iter__(self) -> "LabelCollection":
125+
def __iter__(self) -> "LabelList":
126126
self._index = 0
127127
return self
128128

@@ -155,15 +155,15 @@ class LabelGenerator(PrefetchGenerator):
155155
A container for interacting with a collection of labels.
156156
157157
Use this class if you have larger data. It is slightly harder to work with
158-
than the LabelCollection but will be much more memory efficient.
158+
than the LabelList but will be much more memory efficient.
159159
"""
160160

161161
def __init__(self, data: Generator[Label, None, None], *args, **kwargs):
162162
self._fns = {}
163163
super().__init__(data, *args, **kwargs)
164164

165-
def as_collection(self) -> "LabelCollection":
166-
return LabelCollection(data=list(self))
165+
def as_list(self) -> "LabelList":
166+
return LabelList(data=list(self))
167167

168168
def assign_schema_ids(
169169
self, ontology_builder: OntologyBuilder) -> "LabelGenerator":
@@ -200,7 +200,7 @@ def add_to_dataset(self, dataset: "Entity.Dataset",
200200
Creates data rows from each labels data object and attaches the data to the given dataset.
201201
Updates the label's data object to have the same external_id and uid as the data row.
202202
203-
This is a lot slower than LabelCollection.add_to_dataset but also more memory efficient.
203+
This is a lot slower than LabelList.add_to_dataset but also more memory efficient.
204204
205205
Args:
206206
dataset: labelbox dataset object to add the new data row to
@@ -270,4 +270,4 @@ def __next__(self):
270270
return self._process(value)
271271

272272

273-
LabelContainer = Union[LabelCollection, LabelGenerator]
273+
LabelCollection = Union[LabelList, LabelGenerator]

labelbox/data/annotation_types/feature.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class FeatureSchema(BaseModel):
1111
Could be a annotation, a subclass, or an option.
1212
Schema ids might not be known when constructing these objects so both a name and schema id are valid.
1313
14-
Use `LabelCollection.assign_schema_ids` or `LabelGenerator.assign_schema_ids`
14+
Use `LabelList.assign_schema_ids` or `LabelGenerator.assign_schema_ids`
1515
to retroactively add schema ids by looking them up from the names.
1616
"""
1717
name: Optional[str] = None

labelbox/data/annotation_types/label.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def assign_schema_ids(self, ontology_builder: OntologyBuilder) -> "Label":
8585
Args:
8686
ontology_builder: The ontology that matches the feature names assigned to objects in this dataset
8787
Returns:
88-
LabelCollection. useful for chaining these modifying functions
88+
Label. useful for chaining these modifying functions
8989
"""
9090
tool_lookup, classification_lookup = self._get_feature_schema_lookup(
9191
ontology_builder)

tests/data/annotation_types/test_collection.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66
from labelbox import DataRow
77
from labelbox.data.annotation_types.annotation import ObjectAnnotation
8-
from labelbox.data.annotation_types.collection import (LabelCollection,
8+
from labelbox.data.annotation_types.collection import (LabelList,
99
LabelGenerator)
1010
from labelbox.data.annotation_types.data.raster import RasterData
1111
from labelbox.data.annotation_types.geometry.line import Line
@@ -66,7 +66,7 @@ def test_generator(list_of_labels):
6666

6767
def test_conversion(list_of_labels):
6868
generator = LabelGenerator(list_of_labels)
69-
label_collection = generator.as_collection()
69+
label_collection = generator.as_list()
7070
assert len(label_collection) == len(list_of_labels)
7171
assert [x for x in label_collection] == list_of_labels
7272

@@ -87,7 +87,7 @@ def test_adding_schema_ids():
8787
tools=[Tool(Tool.Type.LINE, name=name, feature_schema_id=schema_id)])
8888
generator = LabelGenerator([label]).assign_schema_ids(ontology)
8989
assert next(generator).annotations[0].schema_id == schema_id
90-
labels = LabelCollection([label]).assign_schema_ids(ontology)
90+
labels = LabelList([label]).assign_schema_ids(ontology)
9191
assert next(labels).annotations[0].schema_id == schema_id
9292
assert labels[0].annotations[0].schema_id == schema_id
9393

@@ -106,7 +106,7 @@ def test_adding_urls(signer):
106106
3)).astype(np.uint8)),
107107
annotations=[])
108108
assert label.data.url != uuid
109-
labels = LabelCollection([label]).add_url_to_data(signer(uuid))
109+
labels = LabelList([label]).add_url_to_data(signer(uuid))
110110
assert label.data.url == uuid
111111
assert next(labels).data.url == uuid
112112
assert labels[0].data.url == uuid
@@ -133,7 +133,7 @@ def test_adding_to_dataset(signer):
133133
assert label.data.url != uuid
134134
assert label.data.external_id == None
135135
assert label.data.uid != dataset.uid
136-
labels = LabelCollection([label]).add_to_dataset(dataset, signer(uuid))
136+
labels = LabelList([label]).add_to_dataset(dataset, signer(uuid))
137137
assert label.data.url == uuid
138138
assert label.data.external_id != None
139139
assert label.data.uid == dataset.uid
@@ -169,6 +169,6 @@ def test_adding_to_masks(signer):
169169
color=[255, 255, 255]))
170170
])
171171
assert label.annotations[0].value.mask.url != uuid
172-
labels = LabelCollection([label]).add_url_to_masks(signer(uuid))
172+
labels = LabelList([label]).add_url_to_masks(signer(uuid))
173173
assert next(labels).annotations[0].value.mask.url == uuid
174174
assert labels[0].annotations[0].value.mask.url == uuid

0 commit comments

Comments
 (0)