Skip to content

Commit 6a56d1f

Browse files
authored
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
1 parent 11ffa75 commit 6a56d1f

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/ansys/dpf/post/dataframe.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -352,15 +352,14 @@ def select(self, **kwargs) -> DataFrame:
352352
indexes=row_indexes,
353353
)
354354

355+
set_index = None
355356
if "time" in fc.labels:
356357
set_index = SetIndex(values=fc.get_available_ids_for_label("time"))
357-
else:
358-
set_index = SetIndex(values=[])
359358

360-
column_indexes = [
361-
results_index,
362-
set_index,
363-
]
359+
column_indexes = [results_index]
360+
if set_index:
361+
column_indexes.append(set_index)
362+
364363
if isinstance(fc, PropertyFieldsContainer):
365364
column_indexes = [results_index]
366365

src/ansys/dpf/post/index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def __init__(
152152

153153
def _evaluate_values(self):
154154
"""Evaluates the values of the MeshIndex."""
155-
if self._scoping_ref is not None:
155+
if self._scoping_ref is not None and self._scoping_ref() is not None:
156156
self._values = self._scoping_ref().ids
157157
else:
158158
# Merge the fields container scoping

tests/test_dataframe.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ def test_dataframe_select(df):
116116
# print(df2)
117117

118118

119+
def test_dataframe_select_no_set_index():
120+
simulation = post.StaticMechanicalSimulation(examples.find_simple_bar())
121+
df = simulation.mesh.coordinates
122+
df2 = df.select(components="X")
123+
assert len(df2.index) == 2
124+
assert df2.index.components.values == ["X"]
125+
assert len(df2.mesh_index.values) == len(df.mesh_index.values)
126+
127+
119128
@pytest.mark.skipif(
120129
not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0,
121130
reason="Fluid capabilities added with ansys-dpf-server 2024.1.pre0.",

0 commit comments

Comments
 (0)