Skip to content

Add item to check for pint array type #4751

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

Closed
wants to merge 3 commits into from
Closed
Changes from 2 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
7 changes: 7 additions & 0 deletions xarray/core/pycompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,10 @@ def is_duck_dask_array(x):
cupy_array_type = (cupy.ndarray,)
except ImportError: # pragma: no cover
cupy_array_type = ()

try:
import pint

pint_array_type = (pint.Quantity,)
except ImportError: # pragma: no cover
pint_array_type = ()
Comment on lines +38 to +44
Copy link
Collaborator

Choose a reason for hiding this comment

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

it seems very strange to me that this would make some of the tests fail. pint didn't release recently, so this should not happen. I tried to rerun, let's see if that changes anything.

Copy link
Collaborator

Choose a reason for hiding this comment

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

this seems to be due to a circular import: pint.compat tries to import xarray objects. pytest.importorskip silences the import error somehow, so we get partially initialized modules. I'm somewhat surprised pint still does that, I thought we switched to comparing names some time ago.

Copy link
Contributor

Choose a reason for hiding this comment

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

It was actually the other way around! We had to change from name-based comparison to actual type checks since both xarray and measurements have a Variable class, and they need to be treated completely differently (see hgrecco/pint#959).

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh, I see. There should be a way to compare without importing (maybe using fully-qualified names like xarray.Variable or xarray.core.variable.Variable), but I guess to really fix this we need figure out #3950.