Skip to content
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

Converting a list of Extension Types that implement __len__ and __getitem__ into a numpy array takes infinite #3243

Open
lilsnore opened this issue Nov 20, 2019 · 0 comments

Comments

@lilsnore
Copy link

@lilsnore lilsnore commented Nov 20, 2019

Having an Extension Type that implements __len__ and __getitem__ like this:

cdef class Foo:

    def __len__(self):
        pass

    def __getitem__(self, key):
        print(f"Calling __getitem__ with key {key}")

If I try to create a numpy array from a list of instances of this Extension Type, it gets stuck calling __getitem__ forever:

> np.asarray([Foo(), Foo()])

Calling __getitem__ with key 0
Calling __getitem__ with key 1
Calling __getitem__ with key 2
Calling __getitem__ with key 3
Calling __getitem__ with key 4
Calling __getitem__ with key 5
...

It only happens when the two methods are together. This behaviour doesn't appear using regular Python.

I am using Python 3.7.3, cython 0.29.12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.