Skip to content

Commit

Permalink
update docstring, whats-new and adapt interp test to test for kwarg p…
Browse files Browse the repository at this point in the history
…assing
  • Loading branch information
martijnvandermarel committed Jul 17, 2024
1 parent 985ccb6 commit 4d39f8e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
3 changes: 3 additions & 0 deletions docs/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ What's new
By `Justus Magin <https://github.com/keewis>`_.
- create a `PintIndex` to allow units on indexed coordinates (:pull:`163`, :issue:`162`)
By `Justus Magin <https://github.com/keewis>`_ and `Benoit Bovy <https://github.com/benbovy>`_.
- fix :py:meth:`Dataset.pint.interp` and :py:meth:`DataArray.pint.interp` bug
failing to pass through arguments (:pull:`270`, :issue:`267`)
By `Martijn van der Marel <https://github.com/martijnvandermarel>`_

0.4 (23 Jun 2024)
-----------------
Expand Down
12 changes: 8 additions & 4 deletions pint_xarray/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,8 @@ def interp(
converted to the units of the indexers first.
.. note::
``kwargs`` is passed unmodified to ``DataArray.interp``
``method``, ``assume_sorted`` and ``kwargs`` are passed unmodified to
``DataArray.interp``.
See Also
--------
Expand Down Expand Up @@ -754,7 +755,8 @@ def interp_like(self, other, method="linear", assume_sorted=False, kwargs=None):
to the units of the indexers first.
.. note::
``kwargs`` is passed unmodified to ``DataArray.interp``
``method``, ``assume_sorted`` and ``kwargs`` are passed unmodified to
``DataArray.interp``.
See Also
--------
Expand Down Expand Up @@ -1483,7 +1485,8 @@ def interp(
to the units of the indexers first.
.. note::
``kwargs`` is passed unmodified to ``Dataset.interp``
``method``, ``assume_sorted`` and ``kwargs`` are passed unmodified to
``DataArray.interp``.
See Also
--------
Expand Down Expand Up @@ -1521,7 +1524,8 @@ def interp_like(self, other, method="linear", assume_sorted=False, kwargs=None):
converted to the units of the indexers first.
.. note::
``kwargs`` is passed unmodified to ``Dataset.interp``
``method``, ``assume_sorted`` and ``kwargs`` are passed unmodified to
``DataArray.interp``.
See Also
--------
Expand Down
22 changes: 15 additions & 7 deletions pint_xarray/tests/test_accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,7 @@ def test_reindex_like(obj, units, other, other_units, expected, expected_units,

@requires_scipy
@pytest.mark.parametrize(
["obj", "units", "indexers", "expected", "expected_units", "error"],
["obj", "units", "indexers", "expected", "expected_units", "error", "kwargs"],
(
pytest.param(
xr.Dataset({"x": ("x", [10, 20, 30]), "y": ("y", [60, 120])}),
Expand All @@ -1446,6 +1446,7 @@ def test_reindex_like(obj, units, other, other_units, expected, expected_units,
xr.Dataset({"x": ("x", [10, 30, 50]), "y": ("y", [0, 120, 240])}),
{"x": "dm", "y": "s"},
None,
None,
id="Dataset-identical units",
),
pytest.param(
Expand All @@ -1455,6 +1456,7 @@ def test_reindex_like(obj, units, other, other_units, expected, expected_units,
xr.Dataset({"x": ("x", [0, 1, 3, 5]), "y": ("y", [0, 2, 4])}),
{"x": "m", "y": "min"},
None,
None,
id="Dataset-compatible units",
),
pytest.param(
Expand All @@ -1464,6 +1466,7 @@ def test_reindex_like(obj, units, other, other_units, expected, expected_units,
None,
{},
ValueError,
None,
id="Dataset-incompatible units",
),
pytest.param(
Expand All @@ -1488,6 +1491,7 @@ def test_reindex_like(obj, units, other, other_units, expected, expected_units,
),
{"a": "kg"},
None,
None,
id="Dataset-data units",
),
pytest.param(
Expand All @@ -1505,6 +1509,7 @@ def test_reindex_like(obj, units, other, other_units, expected, expected_units,
),
{"x": "dm", "y": "s"},
None,
None,
id="DataArray-identical units",
),
pytest.param(
Expand All @@ -1516,12 +1521,13 @@ def test_reindex_like(obj, units, other, other_units, expected, expected_units,
{"x": "dm", "y": "s"},
{"x": Quantity([1, 3, 5], "m"), "y": Quantity([0, 2], "min")},
xr.DataArray(
[[np.nan, 1], [np.nan, 5], [np.nan, np.nan]],
[[0, 1], [0, 5], [0, 0]],
dims=("x", "y"),
coords={"x": ("x", [1, 3, 5]), "y": ("y", [0, 2])},
),
{"x": "m", "y": "min"},
None,
{"bounds_error": False, "fill_value": 0},
id="DataArray-compatible units",
),
pytest.param(
Expand All @@ -1535,6 +1541,7 @@ def test_reindex_like(obj, units, other, other_units, expected, expected_units,
None,
{},
ValueError,
None,
id="DataArray-incompatible units",
),
pytest.param(
Expand All @@ -1543,29 +1550,30 @@ def test_reindex_like(obj, units, other, other_units, expected, expected_units,
dims=("x", "y"),
coords={"x": [10, 20, 30], "y": [60, 120]},
),
{None: "kg"},
"kg",
{"x": [15, 25], "y": [75, 105]},
xr.DataArray(
[[1.25, 1.75], [3.25, 3.75]],
dims=("x", "y"),
coords={"x": [15, 25], "y": [75, 105]},
),
{None: "kg"},
"kg",
None,
None,
id="DataArray-data units",
),
),
)
def test_interp(obj, units, indexers, expected, expected_units, error):
def test_interp(obj, units, indexers, expected, expected_units, error, kwargs):
obj_ = obj.pint.quantify(units)

if error is not None:
with pytest.raises(error):
obj.pint.interp(indexers)
obj_.pint.interp(indexers, kwargs=kwargs)
else:
expected_ = expected.pint.quantify(expected_units)

actual = obj_.pint.interp(indexers)
actual = obj_.pint.interp(indexers, kwargs=kwargs)
assert_units_equal(actual, expected_)
assert_identical(actual, expected_)

Expand Down

0 comments on commit 4d39f8e

Please sign in to comment.