Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not force_ndarray_like #234

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
18 changes: 7 additions & 11 deletions pint_xarray/accessors.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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???
Expand Down Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion pint_xarray/tests/test_accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

# make sure scalars are converted to 0d arrays so quantities can
# always be treated like ndarrays
Comment on lines 23 to 24

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this comment should be modified as well?

unit_registry = UnitRegistry(force_ndarray=True)
unit_registry = UnitRegistry(force_ndarray=False)
Quantity = unit_registry.Quantity

nan = np.nan
Expand Down