-
Notifications
You must be signed in to change notification settings - Fork 489
creation functions according to NEP 35 and updated *_like behavior
#1669
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
base: master
Are you sure you want to change the base?
Conversation
|
The changes here look good to me, and as far as I'm aware, that's the same list of functions that I'm aware of that'd be covered by NEP 35. So I'd say go with it, and if something a user needs happens to have been missed, it could be added later? Speaking of adding later, though, would you be able to add code comments (and modify the existing ones that begin with |
|
Seems like some tests with xarray are making CI fail. |
|
thanks, @jthielen, those are some good points. I've tried to address them in the most recent commits, though I suspect to be really useful we'd need to rewrite / restructure the @jules-ch: no idea. Might be because of changes in this PR, I'll have to investigate. |
It seems I'd argue that this is implicit behavior in zeros_like(data, dtype=bool) # old
full_like(data, dtype=bool, fill_value=False) # newHowever, even though we can fix this |
|
another option would be to avoid wrapping |
This is important because `dask` chose not to implement `subok`.
|
this has become tricky... see pydata/xarray#7395 for more details. The most recent commit fixes a bug in To get out of this dead-lock, I think we need to somehow introduce a way to switch between old and new behavior of (and of course, if someone has a better idea I'd be open to that as well) |
Do you want to add a depreciation warning in another PR? |
np.*_likefunctions #882pre-commit run --all-fileswith no errorsFor a more consistent experience with the
*_likefunctions and the functions from NEP 35 (introduced innumpy=1.20, minimum version is1.19.5but could be1.20according to NEP 29), this changes the semantics to:full_likereturn the units offill_value(a non-quantityfill_valueresults an array of the type of the magnitude):empty_likeuse the units of the argument:ones_likeandzero_likea quantity with the units of the argument:likefor creation functions:I'm not sure I got all of the functions that were changed by NEP 35, I couldn't find a comprehensive list. The ones I found are:
arrayasarrayasanyarrayarangeoneszerosemptyfullidentityeyebut I'm almost certain I missed some (
linspacedoes not seem to be included in that list, unfortunately).The definition of all of them except
fullandarangeis pretty simple: just use the units of thelikeargument.For
full, I chose to go with the unit of thefill_valueordimensionlessif the fill value happens not to be a quantity (because by passinglikewe expect a quantity). Forarange, we can go the "units oflike" route, but we can also support something like(the
like=[0] * ureg.kgis important for dispatching, unfortunately)I might be missing something, though, so I'd appreciate someone checking this.
cc @jthielen