Skip to content

Commit

Permalink
Fix DataFrame.select when no set index (#613)
Browse files Browse the repository at this point in the history
* Fix DataFrame.select when no set index

* Remove dead code

* Add test

* Fix MeshIndex.values evaluation

* Fix MeshIndex.values evaluation
  • Loading branch information
PProfizi authored Nov 21, 2024
1 parent 11ffa75 commit 6a56d1f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
11 changes: 5 additions & 6 deletions src/ansys/dpf/post/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion src/ansys/dpf/post/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down

0 comments on commit 6a56d1f

Please sign in to comment.