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

quantify xarray parameters in MathematicalExpression #864

Merged
Merged
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: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

## 0.6.5 (unreleased)

### Fixes

- fix non quantified xarray parameter inputs to `MathematicalExpression` \[{pull}`864`\].

### Dependencies

- require XArray >= 2022.9.0, as `LocalCoordinateSystem` now handles merges correctly \[{pull}`861`\].
- require `xarray >= 2022.9.0`, as `LocalCoordinateSystem` now handles merges correctly \[{pull}`861`\].

## 0.6.4 (09.02.2023)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ dependencies = [
"scipy >=1.4,!=1.6.0,!=1.6.1",
"sympy >=1.6",
"pint >=0.18",
"pint-xarray >=0.2.1",
"pint-xarray >=0.3",
"bottleneck >=1.3.3",
"boltons",
"bidict",
Expand Down
6 changes: 6 additions & 0 deletions weldx/core/math_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def __eq__(self, other):
"""
return self.equals(other, check_parameters=True, check_structural_equality=True)

__hash__ = None

def equals(
self,
other: Any,
Expand Down Expand Up @@ -169,6 +171,10 @@ def set_parameters(self, params: ExpressionParameterTypes):
v = xr.DataArray(v[0], dims=v[1])
if not isinstance(v, xr.DataArray):
v = Q_(v)
else: # quantify as dimensionless if no unit provided
if v.weldx.units is None:
v = v.pint.quantify("")
v = v.pint.quantify()
self._parameters[k] = v

@property
Expand Down
8 changes: 6 additions & 2 deletions weldx/tests/asdf_tests/test_asdf_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ def get_xarray_example_dataset():
-------
Dataset for test purposes
"""

temp_data = [
[[15.0, 16.0, 17.0], [18.0, 19.0, 20.0]],
[[21.0, 22.0, 23.0], [24.0, 25.0, 26.0]],
Expand Down Expand Up @@ -847,10 +846,15 @@ class TestMathematicalExpression:
@pytest.mark.parametrize(
"a, b",
[
([1.0, 2.0, 3.0], [4.0, 5.0, 6.0]),
(Q_([1, 2, 3], "m"), Q_([4, 5, 6], "m")),
(
xr.DataArray(Q_([1, 2], "m"), dims=["a"]),
xr.DataArray(Q_([3, 4], "m"), dims=["b"]),
xr.DataArray(Q_([3, 4], "m"), dims=["b"]).pint.dequantify(),
),
(
xr.DataArray([1, 2], dims=["a"]),
xr.DataArray([3, 4], dims=["b"]),
),
(
Q_([1, 2], "m"),
Expand Down