From 63e1cc38cd09d23945536cf9eaebb97a309cffb4 Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Wed, 4 Feb 2026 23:12:29 +0100 Subject: [PATCH 1/2] strip units instead of dequantifying Dequantifying used to work with earlier versions of `xarray` because that used to drop attrs on certain operations, but the new default is to always keep attrs. --- pint_xarray/_expects.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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}." From 542c917d43ce155a828b95adf2c2eb95b1951e0f Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Thu, 5 Feb 2026 00:18:34 +0100 Subject: [PATCH 2/2] whats-new [skip-ci] --- docs/whats-new.rst | 2 ++ 1 file changed, 2 insertions(+) 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) -------------------