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 Any.cast for fields container #1775

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions src/ansys/dpf/core/any.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def _type_to_new_from_get_as_method(self, obj):
data_tree,
custom_type_field,
collection,
fields_container
)

if issubclass(obj, int):
Expand Down Expand Up @@ -190,6 +191,11 @@ def _type_to_new_from_get_as_method(self, obj):
self._api.any_new_from_int_collection,
self._api.any_get_as_int_collection,
)
elif issubclass(obj, fields_container.FieldsContainer):
return (
self._api.any_new_from_fields_container,
self._api.any_get_as_fields_container
)

@staticmethod
def new_from(obj, server=None):
Expand Down
13 changes: 13 additions & 0 deletions tests/test_any.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,16 @@ def test_cast_scoping_any(server_type):
new_entity = any_dpf.cast()

assert entity.location == new_entity.location

@conftest.raises_for_servers_version_under("7.0")
def test_cast_fields_container_any(server_type):
fc = dpf.FieldsContainer(server=server_type)
fc.labels = ["time"]

field1 = dpf.Field(nentities=2,server=server_type)
field1.data = [1, 2, 3, 4, 5, 6]
fc.add_field({"time": 0}, field1)
any_dpf = dpf.Any.new_from(fc)

entity: dpf.FieldsContainer = any_dpf.cast()
assert entity.get_field({"time":0}).size == 6
Loading