-
Notifications
You must be signed in to change notification settings - Fork 471
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
creation functions according to NEP 35 and updated *_like
behavior
#1669
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) # new However, 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.*_like
functions #882pre-commit run --all-files
with no errorsFor a more consistent experience with the
*_like
functions and the functions from NEP 35 (introduced innumpy=1.20
, minimum version is1.19.5
but could be1.20
according to NEP 29), this changes the semantics to:full_like
return the units offill_value
(a non-quantityfill_value
results an array of the type of the magnitude):empty_like
use the units of the argument:ones_like
andzero_like
a quantity with the units of the argument:like
for 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:
array
asarray
asanyarray
arange
ones
zeros
empty
full
identity
eye
but I'm almost certain I missed some (
linspace
does not seem to be included in that list, unfortunately).The definition of all of them except
full
andarange
is pretty simple: just use the units of thelike
argument.For
full
, I chose to go with the unit of thefill_value
ordimensionless
if the fill value happens not to be a quantity (because by passinglike
we expect a quantity). Forarange
, we can go the "units oflike
" route, but we can also support something like(the
like=[0] * ureg.kg
is important for dispatching, unfortunately)I might be missing something, though, so I'd appreciate someone checking this.
cc @jthielen