Skip to content

np.array([], dtype=object) triggers error when copied with copy.deepcopy() #8536

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

Closed
aojeda opened this issue Jan 26, 2017 · 4 comments
Closed

Comments

@aojeda
Copy link

aojeda commented Jan 26, 2017

The following code fails with numpy 1.12.0 (this is the only version we have tested).

>>> arr = np.array([], dtype=object)
>>> copy.deepcopy(arr)
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/IPython/core/interactiveshell.py", line 2821, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-16-e314fe8a32a6>", line 1, in <module>
    copy.deepcopy(arr)
  File "/usr/lib/python3.4/copy.py", line 166, in deepcopy
    y = copier(memo)
ValueError: Iteration of zero-sized operands is not enabled

Note that this code already works if the dtype was not object but, e.g., int or str.

@seberg
Copy link
Member

seberg commented Jan 26, 2017

The error is the new iterator missing the zerosize ok flag, a bit annoying really since you usually want it.... It is gh-8125. CC @pelson in case you have time/want to fix it up.

@seberg
Copy link
Member

seberg commented Jan 26, 2017

Probably a regression in 1.12.

@charris charris added this to the 1.12.1 release milestone Jan 26, 2017
@charris
Copy link
Member

charris commented Jan 29, 2017

@seberg Do you mean that we should implement a zerosize flag for nditer?

@seberg
Copy link
Member

seberg commented Jan 29, 2017

The flag already exists. Though since you have to test for an empty iterator afterwards then, could just as well test before the iterator here probably, since its a single array there is no complexity there.

charris added a commit to charris/numpy that referenced this issue Feb 27, 2017
Deepcopy of empty arrays was failing because the nditer was constructed
without the NPY_ITER_ZEROSIZE_OK flag.

Closes numpy#8536.
charris added a commit to charris/numpy that referenced this issue Mar 4, 2017
Deepcopy of empty arrays was failing because the nditer was constructed
without the NPY_ITER_ZEROSIZE_OK flag.

Closes numpy#8536.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants