You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
object array construction should require explicitly specifying dtype=object #5353
This possibility was raised by #5303 (comment) so I'm moving this topic to its own github issue. Problems like scipy/scipy#4239 among others could be softened by making this change although it could bring backwards compatibility issues.
An intermediate solution, which I suggested in #5844, is an explicit opt-out mechanism, perhaps using __array__ = None. It has the advantage of being backwards compatible, and should have the result that ndarray binops return NotImplemented.
object array coercion : everyone here agrees that actually making these things (= all the times asarray returns an object array when the input is not an object array and when dtype=object was not given explicitly) an error would be a good idea
A while ago I wrote up some "documentation" of how object arrays might work ideally, which includes various special cases and this explicit dtype=object change. If it's of any interest to anyone I put it up here.
@ahaldane: any interest into evolving that into a NEP? (Like a PEP but for
numpy -- would need to be a bit clearer about what was new changes versus
current behavior and what kind of strategy would be used in getting from
here to there, then go to the mailing list for discussion. But that would
be the route to making it closer to reality :-))
On Jul 18, 2015 10:40 AM, "ahaldane" [email protected] wrote:
We should probably get started on this. A deprecation in array creation would be a good place to start. We might have problems with array subclasses that override __new__.
PyArray_GetArrayParamsFromObject might be the place to start, but might be too low level. It isn't called from many places. We should also decide how this interacts with ufuncs, especially with the proposed __numpy_ufunc__. Might be worth adding a temporary __not_an_array__ or some such flag that would serve temporarily to disable automatic array conversion until it is made an error.
I tried implementing the new behavior (and not just the depracation) to avoid automatic object coercion by a simple modification PyArray_GetArrayParamsFromObjectas you suggested.
It looks like a good solution! Only 9 tests fail, all of which are explicitly checking cases like variable-length lists.
Perhaps the solution is as simple as that. I haven't thought about __new__ or ufunc issues yet, although those should already have some test coverage. Ping me when you want to speed up implementation.
Activity
argriffing commentedon Dec 27, 2014
Also #2091 (comment).
mhvk commentedon May 25, 2015
An intermediate solution, which I suggested in #5844, is an explicit opt-out mechanism, perhaps using
__array__ = None. It has the advantage of being backwards compatible, and should have the result thatndarraybinops returnNotImplemented.argriffing commentedon Jul 16, 2015
+1's from notes linked from a mailing list post:
ahaldane commentedon Jul 18, 2015
A while ago I wrote up some "documentation" of how object arrays might work ideally, which includes various special cases and this explicit
dtype=objectchange. If it's of any interest to anyone I put it up here.mhvk commentedon Jul 18, 2015
@ahaldane - thanks, at least for me that was very useful!
njsmith commentedon Jul 18, 2015
@ahaldane: any interest into evolving that into a NEP? (Like a PEP but for
numpy -- would need to be a bit clearer about what was new changes versus
current behavior and what kind of strategy would be used in getting from
here to there, then go to the mailing list for discussion. But that would
be the route to making it closer to reality :-))
On Jul 18, 2015 10:40 AM, "ahaldane" [email protected] wrote:
ahaldane commentedon Jul 19, 2015
@njsmith yeah that might be a good idea. I'll collect my thoughts for a bit and then I'll see if I can rework it into that format.
charris commentedon Aug 7, 2016
We should probably get started on this. A deprecation in array creation would be a good place to start. We might have problems with array subclasses that override
__new__.charris commentedon Aug 7, 2016
PyArray_GetArrayParamsFromObjectmight be the place to start, but might be too low level. It isn't called from many places. We should also decide how this interacts with ufuncs, especially with the proposed__numpy_ufunc__. Might be worth adding a temporary__not_an_array__or some such flag that would serve temporarily to disable automatic array conversion until it is made an error.ahaldane commentedon Sep 4, 2016
I'd be happy to try some work on this sometime soon. I'm travelling for a week, but I'll take a look afterwards.
ahaldane commentedon Jan 17, 2017
Followup:
I tried implementing the new behavior (and not just the depracation) to avoid automatic object coercion by a simple modification
PyArray_GetArrayParamsFromObjectas you suggested.It looks like a good solution! Only 9 tests fail, all of which are explicitly checking cases like variable-length lists.
Perhaps the solution is as simple as that. I haven't thought about
__new__or ufunc issues yet, although those should already have some test coverage. Ping me when you want to speed up implementation.charris commentedon Nov 17, 2018
Another topic for potential BIDS discussion. @stefanv Ping.