10000 BUG: incorrect type for objects whose __len__ fails by ahaldane · Pull Request #7397 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: incorrect type for objects whose __len__ fails #7397

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

Merged
merged 1 commit into from
Mar 9, 2016

Conversation

ahaldane
Copy link
Member
@ahaldane ahaldane commented Mar 9, 2016

Fixes #7393, see discussion there. Caused by a bug introduced in #7266.

This reverts the behavior of the following code be the same as before #7266

class A(object):
    def __init__(self, data):
        self._data = data
    def __getitem__(self, item):
        return type(self)(self._data[item])

d = A([1,2,3])
np.array(d)
# array([A(1), A(2), A(3)], dtype=object)

@ahaldane
Copy link
Member Author
ahaldane commented Mar 9, 2016

Don't merge this, I want to investigate a little more.

@ahaldane
Copy link
Member Author
ahaldane commented Mar 9, 2016

Actually I think my fix in #7266 was the right idea, but there was another bug lurking, which I've now fixed. I was missing a call to PyErr_Clear().

It seems that if PySequence_Length raises an error, and it is not cleared, further calls to PySequence_Length will fail too even for valid sequences. I don't understand why that is. In the debugger I can check that PySequence_Length returns -1 immediately before the call to PyErr_Clear, but immediately after it gives the right result (3) for the example above.

@charris
Copy link
Member
charris commented Mar 9, 2016

Perhaps related to #7399 ?

@charris charris added this to the 1.11.0 release milestone Mar 9, 2016
@njsmith
Copy link
Member
njsmith commented Mar 9, 2016

The patch looks solid to me. @mhvk, any chance you can check if this fixes the astropy issue?

@mhvk
Copy link
Contributor
mhvk commented Mar 9, 2016

I did a quick test and yes this solves #7393.

(With numpy master, still two failing tests, but those are on the way to being solved: #7312, #5706)

@njsmith
Copy link
Member
njsmith commented Mar 9, 2016

Thanks @mhvk!

@njsmith
Copy link
Member
njsmith commented Mar 9, 2016

Oh, and thanks @ahaldane too, of course :-)

njsmith added a commit that referenced this pull request Mar 9, 2016
BUG: incorrect type for objects whose __len__ fails
@njsmith njsmith merged commit cb4b28c into numpy:master Mar 9, 2016
@charris charris mentioned this pull request Mar 10, 2016
@charris charris removed this from the 1.11.0 release milestone Mar 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0