-
Notifications
You must be signed in to change notification settings - Fork 465
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
Expected behavior of np.*_like
functions
#882
Comments
Based on the conversation in #905, this is being provisionally implemented with the first option ("Have |
it turns out that the current definition of What if we defined those as: zeros_like(q) == full_like(q, fill_value=Quantity(0, q.units))
ones_like(q) == full_like(q, fill_value=Quantity(1, q.units)) and keep What do you think, @jthielen? Edit: the appropriate non-quantity can still be created using |
No opposition from me! The initial implementation was based on what made sense at the time, but was provisional based on not yet seeing what usage was like in real codebases. Would pint need some form of deprecation cycle for this change in behavior, or can we assume that usage of these functions was uncommon due to unclear expected behavior? |
Not sure. However, given that getting that result is basically just the result of the underlying array (and the alternative is backwards compatible) I'd say the only thing necessary is to clearly document that in the release notes? For reference, instead of ones_like(q) we'd need to use ones_like(q.magnitude) |
Based on discussions in pydata/xarray#3238, it is unclear what the expected behavior of numpy functions like
zeros_like
,ones_like
, andempty_like
is with pint quantities (and depending on that behavior, howfull_like
should behave), in reference to their eventual__array_function__
implementation in pint.The two possibilities discussed there were:
zeros_like
,ones_like
, andempty_like
return base zeros, ones, or empty ndarrays, respectively, and havefull_like
simply match the unit of thefill_value
argumentzeros_like
,ones_like
, andempty_like
return quantities of zeros, ones, or empty in the same unit as theother
argumentfull_like
other
fill_value
fill_value
only if it matches dimensionality withother
, raising an error otherwisefill_value
andother
or not?Relevant discussion quoted from pydata/xarray#3238:
@keewis:
@jthielen:
@keewis:
@jthielen:
The text was updated successfully, but these errors were encountered: