Skip to content

Problems with test_expects with the lates version of xarray #360

@avalentino

Description

@avalentino

With Xarray v2025.12.0 I get the following unit test errors:

$ python3 -m pytest pint_xarray/tests/test_expects.py::TestExpects
=========================================================== test session starts ===========================================================
platform linux -- Python 3.13.11, pytest-9.0.2, pluggy-1.6.0
Matplotlib: 3.10.7+dfsg1
Freetype: 2.14.1
rootdir: /home/antonio/debian/git/pint-xarray
configfile: pyproject.toml
plugins: mock-3.15.1, recording-0.13.4, anyio-4.11.0, zarr-3.1.5, typeguard-4.4.4, hypothesis-6.150.0, mpl-0.17.0, timeout-2.4.0, cov-5.0.0, asyncio-1.3.0, xdist-3.8.0, requests_mock-1.12.1, mypy-plugins-3.2.0
asyncio: mode=Mode.STRICT, debug=False, asyncio_default_fixture_loop_scope=None, asyncio_default_test_loop_scope=function
collected 28 items                                                                                                                        

pint_xarray/tests/test_expects.py ..F.........F...............                                                                      [100%]

================================================================ FAILURES =================================================================
_____________________________________________ TestExpects.test_args[values2-units2-expected2] _____________________________________________

self = <pint_xarray.tests.test_expects.TestExpects object at 0x77d9f5b4cfc0>
values = (<xarray.DataArray ()> Size: 8B
<Quantity(4, 'kilometer')>, 2), units = ('m', None, None)
expected = <xarray.DataArray ()> Size: 8B
array(2000)

    @pytest.mark.parametrize(
        ["values", "units", "expected"],
        (
            ((ureg.Quantity(1, "m"), 2), ("mm", None, None), 500),
            ((ureg.Quantity(1, "m"), ureg.Quantity(0.5, "s")), ("mm", "ms", None), 2),
            (
                (xr.DataArray(4).pint.quantify("km"), 2),
                ("m", None, None),
                xr.DataArray(2000),
            ),
            (
                (
                    xr.DataArray([4, 2, 0]).pint.quantify("cm"),
                    xr.DataArray([4, 2, 1]).pint.quantify("mg"),
                ),
                ("m", "g", None),
                xr.DataArray([10, 10, 0]),
            ),
            (
                (ureg.Quantity(16, "m"), 2, ureg.Quantity(4, "s")),
                ("mm", None, "ms"),
                2,
            ),
        ),
    )
    def test_args(self, values, units, expected):
        @pint_xarray.expects(*units)
        def func(a, b, c=1):
            return a / (b * c)
    
        actual = func(*values)
    
        if isinstance(actual, xr.DataArray):
>           xr.testing.assert_identical(actual, expected)
E           AssertionError: Left and right DataArray objects are not identical
E           Attributes only on the left object:
E               units: meter

pint_xarray/tests/test_expects.py:47: AssertionError
____________________________________________ TestExpects.test_kwargs[values3-units3-expected3] ____________________________________________

self = <pint_xarray.tests.test_expects.TestExpects object at 0x77d9f5a592b0>
values = {'a': <xarray.DataArray ()> Size: 8B
<Quantity(4, 'kilometer')>, 'b': 2}, units = {'a': 'm', 'b': None, 'c': None}
expected = <xarray.DataArray ()> Size: 8B
array(4000)

    @pytest.mark.parametrize(
        ["values", "units", "expected"],
        (
            (
                {"a": ureg.Quantity(1, "m"), "b": 2},
                {"a": "mm", "b": None, "c": None},
                1000,
            ),
            (
                {"a": 2, "b": ureg.Quantity(100, "cm")},
                {"a": None, "b": "m", "c": None},
                4,
            ),
            (
                {"a": ureg.Quantity(1, "m"), "b": ureg.Quantity(0.5, "s")},
                {"a": "mm", "b": "ms", "c": None},
                4,
            ),
            (
                {"a": xr.DataArray(4).pint.quantify("km"), "b": 2},
                {"a": "m", "b": None, "c": None},
                xr.DataArray(4000),
            ),
            (
                {
                    "a": xr.DataArray([4, 2, 0]).pint.quantify("cm"),
                    "b": xr.DataArray([4, 2, 1]).pint.quantify("mg"),
                },
                {"a": "m", "b": "g", "c": None},
                xr.DataArray([20, 20, 0]),
            ),
        ),
    )
    def test_kwargs(self, values, units, expected):
        @pint_xarray.expects(**units)
        def func(a, b, c=2):
            return a / b * c
    
        actual = func(**values)
    
        if isinstance(actual, xr.DataArray):
>           xr.testing.assert_identical(actual, expected)
E           AssertionError: Left and right DataArray objects are not identical
E           Attributes only on the left object:
E               units: meter

pint_xarray/tests/test_expects.py:149: AssertionError
========================================================= short test summary info =========================================================
FAILED pint_xarray/tests/test_expects.py::TestExpects::test_args[values2-units2-expected2] - AssertionError: Left and right DataArray objects are not identical
FAILED pint_xarray/tests/test_expects.py::TestExpects::test_kwargs[values3-units3-expected3] - AssertionError: Left and right DataArray objects are not identical
====================================================== 2 failed, 26 passed in 4.69s =======================================================

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions