-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Pint support for DataArray #3643
Conversation
While trying to get the tests to pass, I encountered a few issues:
|
The bivariate ufunc test is fixed by hgrecco/pint#951.
filler = np.full_like(np.resize(trimmed_data, shape), fill_value, dtype=dtype) instead of xarray/xarray/core/variable.py Lines 1105 to 1112 in 651f27f
pint would have to implement np.resize ). However, that would not work for dask arrays so I'm not sure what to do.
if bottleneck_move_func is not None and not isinstance(
self.obj.data, dask_array_type
) and not hasattr(self.obj.data, "__array_function__"): instead of Lines 363 to 365 in 651f27f
pint to implement np.pad .
Edit: I added it, but this still requires Unless I missed something, these should be the only issues left for |
4863205
to
61c3eb9
Compare
@jthielen, it looks like this needs |
No problem at all to add these! See hgrecco/pint#956. |
956: Add np.pad and np.resize implementations r=hgrecco a=jthielen As requested in pydata/xarray#3643 (comment), this PR adds implementations for `np.pad` and `np.resize`, with accompanying tests. - ~~Closes (insert issue number)~~ (#905 follow-up) - [x] Executed ``black -t py36 . && isort -rc . && flake8`` with no errors - [x] The change is fully covered by automated unit tests - [x] Documented in docs/ as appropriate - ~~Added an entry to the CHANGES file~~ (#905 follow-up) Co-authored-by: Jon Thielen <github@jont.cc>
if you merge from master you should get all green on the upstream-dev test now |
normally, this should work, but the documentation mismatches the implementation of searchsorted and names the keys as `keys` instead of `v`
54e6fde
to
308df31
Compare
A few updates on the progress here: The implementation of The failure of
|
LGTM! Thanks as ever @keewis |
I put in an issue |
thanks, @max-sixty. |
it seems we can't use
Edit: actually, that smells like a type hierarchy issue, as discussed in hgrecco/pint#845 and dask/dask#5329 |
Ugh. Trying to add To resolve this, the type registration mentioned in #1617 and xarray/xarray/core/arithmetic.py Line 23 in ba9f822
might help? |
2031b52
to
79430f0
Compare
I don't know much about this stuff can't pint have just a list of handled types and return |
see dask/dask#5329 (comment). Basically, Actually, |
@keewis Is part of the specific problem that Pint has a guarded import of xarray when defining its upcast types? Would it help if it checked for the fully qualified class name instead? |
Also, after glancing through all this, it seems like xarray is dealing inconsistently with the type casting hierarchy:
Should this be its own issue? |
Definitely, even if it's just to clarify why we accept different types in those functions: I think |
IMO @keewis you should merge this if you think its ready.
open an issue for this? |
see #3950 Merging: sure, I just wanted to avoid merging my own PRs without a final review |
* upstream/master: (39 commits) Pint support for DataArray (pydata#3643) Apply blackdoc to the documentation (pydata#4012) ensure Variable._repr_html_ works (pydata#3973) Fix handling of abbreviated units like msec (pydata#3998) full_like: error on non-scalar fill_value (pydata#3979) Fix some code quality and bug-risk issues (pydata#3999) DOC: add pandas.DataFrame.to_xarray (pydata#3994) Better chunking error messages for zarr backend (pydata#3983) Silence sphinx warnings (pydata#3990) Fix distributed tests on upstream-dev (pydata#3989) Add multi-dimensional extrapolation example and mention different behavior of kwargs in interp (pydata#3956) keep attrs in interpolate_na (pydata#3970) actually use preformatted text in the details summary (pydata#3978) facetgrid: Ensure that colormap params are only determined once. (pydata#3915) RasterioDeprecationWarning (pydata#3964) Empty line missing for DataArray.assign_coords doc (pydata#3963) New coords to existing dim (doc) (pydata#3958) implement a more threadsafe call to colorbar (pydata#3944) Fix wrong order of coordinate converted from pd.series with MultiIndex (pydata#3953) Updated list of core developers (pydata#3943) ...
…k-issues * upstream/master: (22 commits) support darkmode (pydata#4036) Use literal syntax instead of function calls to create the data structure (pydata#4038) Add template xarray object kwarg to map_blocks (pydata#3816) Transpose coords by default (pydata#3824) Remove broken test for Panel with to_pandas() (pydata#4028) Allow warning with cartopy in docs plotting build (pydata#4032) Support overriding existing variables in to_zarr() without appending (pydata#4029) chore: Remove unnecessary comprehension (pydata#4026) fix to_netcdf docstring typo (pydata#4021) Pint support for DataArray (pydata#3643) Apply blackdoc to the documentation (pydata#4012) ensure Variable._repr_html_ works (pydata#3973) Fix handling of abbreviated units like msec (pydata#3998) full_like: error on non-scalar fill_value (pydata#3979) Fix some code quality and bug-risk issues (pydata#3999) DOC: add pandas.DataFrame.to_xarray (pydata#3994) Better chunking error messages for zarr backend (pydata#3983) Silence sphinx warnings (pydata#3990) Fix distributed tests on upstream-dev (pydata#3989) Add multi-dimensional extrapolation example and mention different behavior of kwargs in interp (pydata#3956) ...
This is part of the effort to add support for pint (see #3594) on
DataArray
. This depends on #3611, so we should merge that first.black . && mypy . && flake8
whats-new.rst
for all changes andapi.rst
for new APIlist of failing tests from #3594:
__init__
: Needs unit support in IndexVariable, blocked by Explicit indexes in xarray's data-model (Future of MultiIndex) #1603pint
currently does not implementprod
np.median
returns a numpy scalar instead of aDataArray
becauseDataArray
does not implement__array_function__
rank
only works withnumpy.ndarray
(usesbottleneck
)ffill
,bfill
: usesbottleneck
, which does not support NEP-18?where
: works (but the choice of treatingarray(nan)
andarray(0)
as special needs to be discussed)interpolate_na
: enforces the use ofnumpy.vectorize
which does not support NEP18combine_first
: works, but does not test indexing (which should fail)equals
,identical
: works (right nowidentical
returns the same asequals
)drop_sel
,sel
,loc
: indexes strip units (Explicit indexes in xarray's data-model (Future of MultiIndex) #1603)interp
: usesscipy.interpolate.interp1d
which strips unitsinterp_like
: same asinterp
to_unstacked_dataset
: blocked by IndexVariablequantile
: works (but needs a newpint
version since it usesnumpy.nanquantile
rolling
: usesnumpy.lib.stride_tricks.as_strided
which is not supported by NEP18rolling_exp
: numbagg