-
Notifications
You must be signed in to change notification settings - Fork 9
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
Add units to ResultsIndex #330
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,9 +139,15 @@ def test_dataframe_animate(transient_rst): | |
|
||
def test_dataframe_repr(df): | ||
ref = ( | ||
"DataFrame<index=MultiIndex<[MeshIndex<name=\"node_ids\", dtype=<class 'int'>>, " | ||
"Index<name=\"components\", dtype=<class 'str'>>]>, columns=MultiIndex<[ResultIndex<['U']>, " # noqa: E501 | ||
"SetIndex<values=[1]>]>>" | ||
"DataFrame<" | ||
"index=MultiIndex<[" | ||
"MeshIndex<name=\"node_ids\", dtype=<class 'int'>>, " | ||
"Index<name=\"components\", dtype=<class 'str'>>" | ||
"]>, " | ||
"columns=MultiIndex<[" | ||
"ResultIndex<['U (m)']>, " | ||
"SetIndex<values=[1]>" | ||
"]>>" | ||
) | ||
assert repr(df) == ref | ||
Comment on lines
141
to
152
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might want to use this pytest plugin to automatize "golden" tests https://github.com/oprypin/pytest-golden#pytest-golden Feel free to ping me about this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh nice, thx @germa89, I did not know this plugin! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you know if it works well for numerical values? |
||
|
||
|
@@ -151,7 +157,7 @@ def test_dataframe_str(transient_rst): | |
df = simulation.displacement(all_sets=True) | ||
print(df) | ||
ref = """ | ||
results U ... | ||
results U (m) ... | ||
set_ids 1 2 3 4 5 6 ... | ||
node_ids components ... | ||
525 X 0.0000e+00 4.8506e-05 2.3022e-04 6.5140e-04 1.4812e-03 2.9324e-03 ... | ||
|
@@ -166,7 +172,7 @@ def test_dataframe_str(transient_rst): | |
df2 = df.select(node_ids=525) | ||
print(df2) | ||
ref = """ | ||
results U ... | ||
results U (m) ... | ||
set_ids 1 2 3 4 5 6 ... | ||
node_ids components ... | ||
525 X 0.0000e+00 4.8506e-05 2.3022e-04 6.5140e-04 1.4812e-03 2.9324e-03 ... | ||
|
@@ -179,7 +185,7 @@ def test_dataframe_str(transient_rst): | |
print(df) | ||
print(df._fc[0].get_entity_data_by_id(391)) | ||
ref = """ | ||
results S | ||
results S (Pa) | ||
set_ids 35 | ||
element_ids components | ||
391 XX (1) -3.2780e+05 | ||
|
@@ -194,7 +200,7 @@ def test_dataframe_str(transient_rst): | |
df2 = df.select(components="YY") | ||
print(df2) | ||
ref = """ | ||
results S | ||
results S (Pa) | ||
set_ids 35 | ||
element_ids components | ||
391 YY (1) 1.3601e+06 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from ansys.dpf.post.index import ResultsIndex | ||
|
||
|
||
class TestResultsIndex: | ||
def test_results_index(self): | ||
result_index = ResultsIndex(values=["U", "V", "A"], units=None) | ||
ref = "ResultIndex<['U', 'V', 'A']>" | ||
assert repr(result_index) == ref | ||
result_index = ResultsIndex(values=["U", "V", "A"], units=["m", "m/s"]) | ||
ref = "ResultIndex<['U (m)', 'V (m/s)', 'A']>" | ||
assert repr(result_index) == ref | ||
result_index = ResultsIndex(values=["U", "V", "A"], units=["m", None, "m/s^2"]) | ||
ref = "ResultIndex<['U (m)', 'V', 'A (m/s^2)']>" | ||
assert repr(result_index) == ref | ||
result_index = ResultsIndex(values=["U", "V", "A"], units=["m", "m/s", "m/s^2"]) | ||
ref = "ResultIndex<['U (m)', 'V (m/s)', 'A (m/s^2)']>" | ||
assert repr(result_index) == ref | ||
|
||
def test_results_index_units(self): | ||
result_index = ResultsIndex(values=["U", "V", "A"], units=None) | ||
assert result_index.units == [None, None, None] | ||
result_index = ResultsIndex(values=["U", "V", "A"], units=["m", "m/s"]) | ||
assert result_index.units == ["m", "m/s", None] | ||
result_index = ResultsIndex(values=["U", "V", "A"], units=["m", None, "m/s^2"]) | ||
assert result_index.units == ["m", None, "m/s^2"] | ||
result_index = ResultsIndex(values=["U", "V", "A"], units=["m", "m/s", "m/s^2"]) | ||
assert result_index.units == ["m", "m/s", "m/s^2"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably we want to avoid writing
"()"
ifunit
isNone
. :)And personally, I read better the
if
before thefor
. But this is a nit pick :).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @germa89! Thx for the review! Just to nit pick too, the original line 174 does actually write
""
ifunit
isNone
;)Also, the
if
after thefor
is because the operation of adding the unit to the string rep is not needed forNone
values of units, which is all we are adding in theif
.Thus having the
if
before thefor
might be a bit more readable, but is adds unnecessary operations. What I will do is add comments so it is more readable because you are right, it is not really readable.