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
MAINT: Simplify element setting and use it for filling #20924
Conversation
4d51121
to
f5d683a
Compare
This is also fairly important, since it finally full consolidates what it means to set an item (at least to the extend possible). We also really should add This means that a followup will be to change all |
f5d683a
to
eebbd6c
Compare
Didn't we discuss this at the triage meeting and decide to go ahead with it? |
Yeah, although there is that weird thing about whether or not to unpack I think we should just do this and go ahead, but I do need to ping the list and we may want to follow-up on the precise route. |
Did the answers on the list help? |
Not quite settled, considering that Stéfan and you seem to have different opinions :). I would go with this (i.e. store the array directly), for now. Not because I am 100% sure that this is the best way, but because my guess is that it is so much more common for us to do that (item assignment), that it probably barely matters to go ahead and change |
I would like to go for this now that we are early in the next release cycle. Yes, there is some uncertainty about object arrays, but I prefer the consistency for now, and worry about flipping the switch later (rather than caring about keeping this one corner case on potential future behavior). |
Here is the mailing list discussion. Can we add some documentation to |
This slightly modifies the behaviour of `arr.fill()` to be `arr.fill(scalar)`, i.e. match `arr1d[0] = scalar`, rather than `arr.fill(np.asarray(scalar))`, which subtely different! (Note that object was already special cased to have the scalar logic.) Otherwise, `PyArray_Pack` is now the actual, full featured, "scalar" assignment logic. It is a bit strange due to that quantity/masked array issue, but there is nothing to be done about it. The simplifications in `PyArray_AssignFromCache` should not cause any change in practice, because non 0-D arrays would have been rejected earlier on in that path. (Basically, it does not need the full `PyArray_Pack` logic, but that is fine, I intially split the two, but consolidated them again.)
Co-authored-by: Matti Picus <matti.picus@gmail.com>
f301fb1
to
5d6d9a3
Compare
5d6d9a3
to
20b75ea
Compare
>>> a[...] = np.array(3) | ||
>>> a | ||
array([3, 3], dtype=object) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, added this chunk as an example (and tweaked the release not a tiny bit). Not sure whether it isn't a bit much, but I guess it is just at the end of the examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, thanks
Thanks @seberg |
This slightly modifies the behaviour of
arr.fill()
to bearr.fill(scalar)
, i.e. matcharr1d[0] = scalar
, rather thanarr.fill(np.asarray(scalar))
, which subtely different!(Note that object was already special cased to have the scalar
logic.)
Otherwise,
PyArray_Pack
is now the actual, full featured, "scalar"assignment logic. It is a bit strange due to that quantity/masked
array issue, but there is nothing to be done about it.
The simplifications in
PyArray_AssignFromCache
should not causeany change in practice, because non 0-D arrays would have been
rejected earlier on in that path.
(Basically, it does not need the full
PyArray_Pack
logic, but thatis fine, I intially split the two, but consolidated them again.)