diff --git a/docs/whats-new.rst b/docs/whats-new.rst index a00ba543..48cebe3c 100644 --- a/docs/whats-new.rst +++ b/docs/whats-new.rst @@ -6,6 +6,8 @@ What's new -------------------- - Properly rename the coordinate units (:pull:`351`). By `Justus Magin `_. +- Don't rely on ``xarray``'s default behavior regarding ``attrs`` in :py:func:`pint_xarray.expects` (:issue:`360`, :pull:`367`) + By `Justus Magin `_. 0.6.0 (31 Aug 2025) ------------------- diff --git a/pint_xarray/_expects.py b/pint_xarray/_expects.py index 24a5ffdb..44df3e98 100644 --- a/pint_xarray/_expects.py +++ b/pint_xarray/_expects.py @@ -8,7 +8,7 @@ import xarray as xr from pint_xarray.accessors import get_registry -from pint_xarray.conversion import extract_units +from pint_xarray.conversion import extract_units, strip_units from pint_xarray.itertools import zip_mappings variable_parameters = (Parameter.VAR_POSITIONAL, Parameter.VAR_KEYWORD) @@ -185,7 +185,7 @@ def wrapper(*args, **kwargs): if isinstance(value, pint.Quantity): params.arguments[name] = value.m_as(units) elif isinstance(value, (xr.DataArray, xr.Dataset)): - params.arguments[name] = value.pint.to(units).pint.dequantify() + params.arguments[name] = strip_units(value.pint.to(units)) else: raise TypeError( f"Attempting to convert non-quantity {value} to {units}."