From cf806098f5557112e0095b0629ef0a77f83ed594 Mon Sep 17 00:00:00 2001 From: Yves Delley Date: Wed, 13 Dec 2023 17:43:27 +0100 Subject: [PATCH 1/2] do not force_ndarray_like --- pint_xarray/accessors.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/pint_xarray/accessors.py b/pint_xarray/accessors.py index 08183ed1..1a891f28 100644 --- a/pint_xarray/accessors.py +++ b/pint_xarray/accessors.py @@ -1,5 +1,6 @@ # TODO is it possible to import pint-xarray from within xarray if pint is present? import itertools +import warnings import pint from pint import Unit @@ -16,21 +17,21 @@ def setup_registry(registry): """set up the given registry for use with pint_xarray - Namely, it enables ``force_ndarray_like`` to make sure results are always - duck arrays. + Does nothing (returns the registry unchanged). + It used to enable ``force_ndarray_like`` to make sure results are always + duck arrays, but that caused more problems than it solved. + Kept for backwards compatibility. Parameters ---------- registry : pint.UnitRegistry The registry to modify """ - if not registry.force_ndarray and not registry.force_ndarray_like: - registry.force_ndarray_like = True - + warnings.warn("setup_registry is not needed anymore", DeprecationWarning) return registry -default_registry = setup_registry(pint.get_application_registry()) +default_registry = pint.get_application_registry() # TODO could/should we overwrite xr.open_dataset and xr.open_mfdataset to make # them apply units upon loading??? @@ -114,11 +115,6 @@ def get_registry(unit_registry, new_units, existing_units): "using multiple unit registries in the same object is not supported" ) - if not unit_registry.force_ndarray_like and not unit_registry.force_ndarray: - raise ValueError( - "invalid registry. Please enable 'force_ndarray_like' or 'force_ndarray'." - ) - return unit_registry From 69e04819c5d9dd1ff49f7060d1df0a0c321a8b2f Mon Sep 17 00:00:00 2001 From: Yves Delley Date: Fri, 15 Dec 2023 09:49:24 +0100 Subject: [PATCH 2/2] neither set force_ndarray_like in the tests --- pint_xarray/tests/test_accessors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pint_xarray/tests/test_accessors.py b/pint_xarray/tests/test_accessors.py index 46d4ed61..9096af6e 100644 --- a/pint_xarray/tests/test_accessors.py +++ b/pint_xarray/tests/test_accessors.py @@ -22,7 +22,7 @@ # make sure scalars are converted to 0d arrays so quantities can # always be treated like ndarrays -unit_registry = UnitRegistry(force_ndarray=True) +unit_registry = UnitRegistry(force_ndarray=False) Quantity = unit_registry.Quantity nan = np.nan