-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: Segfault for classes with deceptive __len__ #7266
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
Hmm, failures in python2 are fixed by removing the code block a few lines above, which has the comment |
OK, I have to leave this for a little bit. Here are notes so I remember what I was thinking. The issue is that python2 and python3 give different results for the example in #7264. The first reason is this block marked However, if we remove that block at least we now get a This is caused by yet another call to I am tempted to just remove the first block above, and live with the fact that we get different ValueErrors in python2 and python3. However that probably means there is a bug that will turn up when more people convert from python2 to python3. |
5965905
to
f98673b
Compare
Fixed up, should be ready. Is a release note needed? I decided to remove the code blocks involving This does mean a small change in behavior for python2: class C:
def __init__(self):
pass
def __getitem__(self, ind):
if ind in [0,1]:
return ind
else:
raise IndexError()
def __len__(self):
return 2
np.array([C()]) Old result:
New result:
In words, if a class defines both However, as before, if |
@anntzer How did you discover the error? I think a note would be appropriate, put it in
|
I was trying to figure out what rules numpy uses to decide between creating an object array and trying to iterate over the array and get floats out of that (basically my starting point was #7233), so at some point I basically wrote the same class as you did and saw the segfault. |
492c105
to
e3df40e
Compare
That function does not exist in python3, causing differing behavior in python2 vs python3. This will slightly affect dtype detection when creating arrays from user-supplied object, in cases where an object array might be produced.
e3df40e
to
bf6017a
Compare
BUG: Segfault for classes with deceptive __len__
Thanks @ahaldane . |
Thanks, and as Post Script note: I updated the final version to remove dead code in |
Backport #7266, BUG: Segfault for classes with deceptive __len__
Fixes #7264