Use definition of DTypeLike from Numpy if found#4941
Use definition of DTypeLike from Numpy if found#4941max-sixty merged 2 commits intopydata:masterfrom
Conversation
And fall back to original definition with older versions of numpy
|
Hello @jenshnielsen! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2021-02-22 08:09:19 UTC |
max-sixty
left a comment
There was a problem hiding this comment.
Thanks for the PR @jenshnielsen , we're happy to have you as a contributor.
This looks good! We do have a mechanism for checking versions elsewhere in the code using LooseVersion, but this approach works too. IIUC the existing code may break type-checking, but the code will still run on numpy<1.20; please let me know if that's not the case.
I'm not that well-versed here, so I'll wait a day for merging to see whether others have comments.
|
@max-sixty Thanks :)
Yes the existing code which is now the fallback could be considered wrong as it does not match the definitions that numpy ships. The numpy definition is: So one could add None and type but should probably omit the rest in order to not replicate too much of numpys internal type definitions |
|
Thanks. Looks good. IMHO typing is a nice-to-have far-from-complete part of xarray & I wouldn't bother about backwards compatibility (of the typing). Up to you. |
|
Great, merging. Thanks @jenshnielsen ! |
|
Thanks @max-sixty @mathause |
* upstream/master: (46 commits) pin netCDF4=1.5.3 in min-all-deps (pydata#4982) fix matplotlib errors for single level discrete colormaps (pydata#4256) Adapt exception handling in CFTimeIndex.__sub__ and __rsub__ (pydata#5006) Update options.py (pydata#5000) Adjust tests to use updated pandas syntax for offsets (pydata#4537) add a combine_attrs parameter to Dataset.merge (pydata#4895) Support for dask.graph_manipulation (pydata#4965) raise on passing axis to Dataset.reduce methods (pydata#4940) Whatsnew for 0.17.1 (pydata#4963) Refinements to how-to-release (pydata#4964) DOC: add example for reindex (pydata#4956) DOC: rm np import (pydata#4949) Add 0.17.0 release notes (pydata#4953) document update as inplace (pydata#4932) bump the dependencies (pydata#4942) Upstream CI: limit runtime (pydata#4946) typing for numpy 1.20 (pydata#4878) Use definition of DTypeLike from Numpy if found (pydata#4941) autoupdate mypy (pydata#4943) Add DataArrayCoarsen.reduce and DatasetCoarsen.reduce methods (pydata#4939) ...
This allows application of numpy ufuncs to DataArrays to typecheck correctly with Numpy 1.20
E.g. without this fix:
will result in:
While it will type check without issues with this fix.
I have not yet documented this or added tests.
Please let me know if this change is acceptable and I am happy to do that.
pre-commit run --all-fileswhats-new.rst