Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Collection.name #1335

Merged
merged 10 commits into from
Feb 7, 2024
28 changes: 28 additions & 0 deletions src/ansys/dpf/core/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import numpy as np

from ansys.dpf.core.check_version import version_requires
from ansys.dpf.core.server_types import BaseServer
from ansys.dpf.core.scoping import Scoping
from ansys.dpf.core.label_space import LabelSpace
Expand Down Expand Up @@ -74,6 +75,33 @@
# step3: init environment
self._api.init_collection_environment(self) # creates stub when gRPC

@property
@version_requires("8.0")
def name(self):
"""Name of the Collection.

Notes
-----
Available starting with DPF 2024 R2 pre0.

Returns
-------
str
"""
out = self._api.collection_get_name(self)
return out if out != '' else None

Check warning on line 92 in src/ansys/dpf/core/collection.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/collection.py#L91-L92

Added lines #L91 - L92 were not covered by tests

@name.setter
@version_requires("8.0")
def name(self, name: str):
"""Set the name of the Collection.

Notes
-----
Available starting with DPF 2024 R2 pre0.
"""
self._api.collection_set_name(self, name=name)

Check warning on line 103 in src/ansys/dpf/core/collection.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/collection.py#L103

Added line #L103 was not covered by tests

@abc.abstractmethod
def create_subtype(self, obj_by_copy):
pass
Expand Down
12 changes: 12 additions & 0 deletions src/ansys/dpf/gate/collection_grpcapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ def collection_get_num_labels(collection):
def collection_get_label(collection, labelIndex):
return CollectionGRPCAPI._list(collection).labels.labels[labelIndex]

@staticmethod
def collection_get_name(collection):
return CollectionGRPCAPI._list(collection).name

@staticmethod
def collection_set_name(collection, name):
from ansys.grpc.dpf import collection_pb2
request = collection_pb2.UpdateCollectionRequest()
request.collection.CopyFrom(collection._internal_obj)
request.string_properties.update({"name": name})
_get_stub(collection._server).Update(request)

PProfizi marked this conversation as resolved.
Show resolved Hide resolved
@staticmethod
def collection_get_size(collection):
if isinstance(collection._internal_obj, list):
Expand Down
11 changes: 11 additions & 0 deletions tests/test_fieldscontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ def test_create_fields_container(server_type):
assert fc._internal_obj is not None


@pytest.mark.skipif(
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0,
reason="Renaming collections is supported via gRPC starting server version 8.0",
)
def test_rename_fields_container(server_type):
fc = FieldsContainer(server=server_type)
assert fc.name is None
fc.name = "test"
assert fc.name == "test"


def test_empty_index(server_type):
fc = FieldsContainer(server=server_type)
with pytest.raises(IndexError):
Expand Down
Loading