-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
object array creation new conversion to int #3804
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
Comments
Hmmm, this is not quite clear to me. The old behaviour somewhat seems more sensible to me, however this overlaps:
I.e. the numpy type gets converted to the python type in object assignments due to CopyTo behaviour as if |
Or identical, but maybe even closer to the question, |
I am seriously starting to think the change is good, but we should change the behaviour back by also changing that assignment subtlety. It would be a subtle change, but I really can't see why we should lose type information on object array assignments (won't rule out that it can be useful at times, but I think it is rather unexpected) or casting to object. |
@juliantaylor @seberg What is the status here? Sounds like this should be fixed. |
One option may be something like this (likely not exactly this):
I just tried and it creates a couple of test failures, would have to investigate further if that might be an option or the failures are not easy to fix. It would be the change I mentioned above... |
OK, so the problem with that above change is probably "just" that the numpy scalar types call into the ufunc/array machinery for their stuff. This leads to an infinite loop:
kaboom. |
I'm inclined to leave this be for 1.9. @juliantaylor @seberg Thoughts? |
Well, I think the "correct" thing would be to do that change I mentioned. Since that requires some rework of the scalars... As far as I understood the problems scipy had with this are fixed or not very substantial. So, while ideally, I think we basically reverse the current object casting behaviour (reverse in the sense of the |
@seberg OK, I'll leave this open and remove it from the 1.9 blockers. Do you think it should be a 1.10 blocker? That way it won't get completely lost. |
it seems to me it should return a void scalar. Eg:
Edit: Oh I see that's what it originally did |
I think the solution might be to add a new function |
After examining it a little more: I think the problem here is that object arrays have two distinct (sometimes incompatible) functions: 1) to allow arrays containing arbitrary python objects, and 2) to cast numpy-numeric-types to python-numeric-types. The two functions are conflicting in this issue.
Here are a few examples that helped me think about what was going on. The current rule seems to be: If the sub-sequences are the same length cast all elements to the closest compatible type (which may be object/python-types if there is any non-numeric element). If the sub-sequences are different length, create an object array but do not cast to object.
However we do it, I think there should be a way of creating object arrays both with and without casting to python types. What should that look like? One far-out idea is doing |
It looks to me like a valid bug, but it's not a 1.10 blocker in any sense.
|
I agree with @njsmith, it's not urgent |
Bumbing up to 1.12 release, and will continue to do so until someone steps up to fix this. |
I am going to close this. I think that gh-16876 basically half covers this, and its so many years ago that we should not worry about the initial "regression" anymore, I think. |
#3696 introduced a suble change in behavior for record arrays
before the PR it keept the numpy scalars
now it converts them to python integers.
The reason seems to be that old code just copied the points of the object, while the new code goes through PyArray_CopyInto which calls dtype->get_element on each entry.
The get_elemnt of int arrays converts it to python integers in python2.
This causes a test failure in scipy where a int type array now compares false to the np.int32 type array (test_stats.py)
I'm not sure whats the best way to fix that or if it even should be fixed.
The text was updated successfully, but these errors were encountered: