Skip to content
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
2 changes: 2 additions & 0 deletions ci/install-upstream-wheels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ python -m pip install \
--pre \
--upgrade \
pyarrow
# manually install `pint` to pull in new dependencies
python -m pip install --upgrade pint
python -m pip install \
--no-deps \
--upgrade \
Expand Down
13 changes: 5 additions & 8 deletions xarray/tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
# always be treated like ndarrays
unit_registry = pint.UnitRegistry(force_ndarray_like=True)
Quantity = unit_registry.Quantity
no_unit_values = ("none", None)


pytestmark = [
Expand Down Expand Up @@ -91,17 +92,13 @@ def array_strip_units(array):


def array_attach_units(data, unit):
if isinstance(data, Quantity):
if isinstance(data, Quantity) and data.units != unit:
raise ValueError(f"cannot attach unit {unit} to quantity {data}")

try:
quantity = data * unit
except np.core._exceptions.UFuncTypeError:
if isinstance(unit, unit_registry.Unit):
raise

quantity = data
if unit in no_unit_values or (isinstance(unit, int) and unit == 1):
return data

quantity = unit_registry.Quantity(data, unit)
return quantity


Expand Down