Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ansys/dpf/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@

from ansys.dpf.core.collection import CollectionFactory as _CollectionFactory
from ansys.dpf.core.collection import Collection as _Collection
from ansys.dpf.core.label_space import LabelSpace


# register classes for collection types:
Expand Down
8 changes: 7 additions & 1 deletion src/ansys/dpf/core/collection_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,13 @@ def _get_labels(self) -> list:
out.append(self._api.collection_get_label(self, i))
return out

labels = property(_get_labels, set_labels, "labels")
@property
def labels(self) -> list[str]:
return self._get_labels()

@labels.setter
def labels(self, labels: list[str]):
self.set_labels(labels=labels)

def has_label(self, label) -> bool:
"""Check if a collection has a specified label.
Expand Down
14 changes: 13 additions & 1 deletion src/ansys/dpf/core/label_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,22 @@ def _data_processing_core_api(self):
core_api.init_data_processing_environment(self)
return core_api

def fill(self, label_space):
def fill(self, label_space: dict[str, int]):
for key, index in label_space.items():
self._api.label_space_add_data(self, key, index)

def __str__(self):
return str(dict(self))

def __iter__(self):
yield from [
(
self._api.label_space_get_labels_name(self, i),
self._api.label_space_get_labels_value(self, i),
)
for i in range(self._api.label_space_get_size(self))
]

def __dict__(self):
if isinstance(self._internal_obj, dict):
return self._internal_obj
Expand Down
32 changes: 32 additions & 0 deletions tests/test_label_space.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (C) 2020 - 2024 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import ansys.dpf.core as dpf


def test_label_space_(server_type):
reference = {"test": 1, "various": 2}
ls = dpf.LabelSpace(label_space=reference)
assert dict(ls) == reference
assert str(ls)
reference = {"test": 1, "various": 2}
ls.fill(label_space=reference)