From 6a56d1f8b17040fdadce6609ac8f55ba88f1df3e Mon Sep 17 00:00:00 2001 From: Paul Profizi <100710998+PProfizi@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:25:24 +0100 Subject: [PATCH] Fix DataFrame.select when no set index (#613) * Fix DataFrame.select when no set index * Remove dead code * Add test * Fix MeshIndex.values evaluation * Fix MeshIndex.values evaluation --- src/ansys/dpf/post/dataframe.py | 11 +++++------ src/ansys/dpf/post/index.py | 2 +- tests/test_dataframe.py | 9 +++++++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/ansys/dpf/post/dataframe.py b/src/ansys/dpf/post/dataframe.py index e8b68d776..f674baea5 100644 --- a/src/ansys/dpf/post/dataframe.py +++ b/src/ansys/dpf/post/dataframe.py @@ -352,15 +352,14 @@ def select(self, **kwargs) -> DataFrame: indexes=row_indexes, ) + set_index = None if "time" in fc.labels: set_index = SetIndex(values=fc.get_available_ids_for_label("time")) - else: - set_index = SetIndex(values=[]) - column_indexes = [ - results_index, - set_index, - ] + column_indexes = [results_index] + if set_index: + column_indexes.append(set_index) + if isinstance(fc, PropertyFieldsContainer): column_indexes = [results_index] diff --git a/src/ansys/dpf/post/index.py b/src/ansys/dpf/post/index.py index d7a46976a..6c798664d 100644 --- a/src/ansys/dpf/post/index.py +++ b/src/ansys/dpf/post/index.py @@ -152,7 +152,7 @@ def __init__( def _evaluate_values(self): """Evaluates the values of the MeshIndex.""" - if self._scoping_ref is not None: + if self._scoping_ref is not None and self._scoping_ref() is not None: self._values = self._scoping_ref().ids else: # Merge the fields container scoping diff --git a/tests/test_dataframe.py b/tests/test_dataframe.py index f831b0510..4858faaf2 100644 --- a/tests/test_dataframe.py +++ b/tests/test_dataframe.py @@ -116,6 +116,15 @@ def test_dataframe_select(df): # print(df2) +def test_dataframe_select_no_set_index(): + simulation = post.StaticMechanicalSimulation(examples.find_simple_bar()) + df = simulation.mesh.coordinates + df2 = df.select(components="X") + assert len(df2.index) == 2 + assert df2.index.components.values == ["X"] + assert len(df2.mesh_index.values) == len(df.mesh_index.values) + + @pytest.mark.skipif( not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0, reason="Fluid capabilities added with ansys-dpf-server 2024.1.pre0.",