diff --git a/src/ansys/dpf/core/collection_base.py b/src/ansys/dpf/core/collection_base.py index c98cd93cf9..18bc3219ed 100644 --- a/src/ansys/dpf/core/collection_base.py +++ b/src/ansys/dpf/core/collection_base.py @@ -424,11 +424,11 @@ def __getitem__(self, index: int | slice): """ if isinstance(index, slice): # handle slice - indices = list(range( - index.start if index.start else 0, - index.stop, - index.step if index.step else 1 - )) + indices = list( + range( + index.start if index.start else 0, index.stop, index.step if index.step else 1 + ) + ) out_collection = self.__class__() out_collection.set_labels(labels=self._get_labels()) if hasattr(out_collection, "add_entry"): @@ -441,7 +441,7 @@ def __getitem__(self, index: int | slice): for i in indices: func( label_space=self.get_label_space(index=i), - entry=self._get_entries(label_space_or_index=i) + entry=self._get_entries(label_space_or_index=i), ) return out_collection self_len = len(self) diff --git a/tests/test_collection.py b/tests/test_collection.py index cb73753ca3..017ec3211a 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -245,14 +245,14 @@ def test_connect_collection_workflow(server_type, subtype_creator): assert out is not None assert len(out) == 1 + def test_generic_data_containers_collection_slice(server_type): coll = GenericDataContainersCollection(server=server_type) coll.labels = ["id1", "id2"] for i in range(5): coll.add_entry( - label_space={"id1": i, "id2": 0}, - entry=create_dummy_gdc(server_type=server_type) + label_space={"id1": i, "id2": 0}, entry=create_dummy_gdc(server_type=server_type) ) assert len(coll) == 5 print(coll) @@ -268,7 +268,7 @@ def test_string_containers_collection_slice(server_type): for i in range(5): coll.add_entry( label_space={"id1": i, "id2": 0}, - entry=create_dummy_string_field(server_type=server_type) + entry=create_dummy_string_field(server_type=server_type), ) assert len(coll) == 5 print(coll)