-
Notifications
You must be signed in to change notification settings - Fork 262
FIX: Accept dtype parameter to ArrayProxy.__array__ #844
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #844 +/- ##
==========================================
- Coverage 90.02% 90.01% -0.01%
==========================================
Files 98 98
Lines 12452 12441 -11
Branches 2190 2191 +1
==========================================
- Hits 11210 11199 -11
Misses 890 890
Partials 352 352
Continue to review full report at Codecov.
|
I'm inclined to drop |
The upside of If so, then I don't see much need for |
I'd be happy to add a more complete description of the Just to concisely summarize:
IDK if that affects your thinking here. |
In my mind this is similar to the recent I'd personally be fine to see |
Okay. I've dropped |
6572302
to
99b368b
Compare
71a2899
to
6856c31
Compare
43c23d6
to
70987fb
Compare
Any further comments? I'm inclined to do a second RC after this, to give a bit more testing time. |
At least back through numpy 1.12, the
__array__
protocol has accepted a dtype parameter.Overall this is poorly documented in numpy (the above link the only place I've seen reference to the
dtype
parameter), but some manual testing seems to indicate it works, and that its absence produces errors in the cases described in #843. Systematic tests are added to the proxy API. Happy to add more, if we can think of specific cases that might trip us up.It occurs to me that this largely replaces the
get_scaled()
method added in #833, with the primary difference being thatget_scaled()
guarantees not to downcast if it can't assure there will be no overflow.get_scaled()
will also make as few copies as possible, while__array__
may make another ifget_scaled(dtype).dtype != np.dtype(dtype)
. If that distinction is not worth drawing, it may be worth removingget_scaled()
before it hits a release, and make the__array__
interface THE way to control dtypes beyondget_fdata()
.One interesting side effect of this is that mask or atlas data that is known to be <=255, but the scale factors are not guaranteed to be
slope = 1, inter = 0
can be retrieved with minimal up-casting via:This is of course quite dangerous, and with the current implementation, non-integer data will be happily coerced into meaningless garbage. Validating coercion or using safer casting rules could be a good idea, but that would also break the following equality by causing the RHS to raise an exception:
All of your thoughts are very welcome.
Fixes #843.
Affects #842.
Follow-up to #833.
cc @jeromedockes @kchawla-pi @adelavega @rmarkello @matthew-brett