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

Bug when building a view of a masked array with field offsets #11645

Open
eduble opened this issue Jul 31, 2018 · 0 comments
Open

Bug when building a view of a masked array with field offsets #11645

eduble opened this issue Jul 31, 2018 · 0 comments

Comments

@eduble
Copy link

eduble commented Jul 31, 2018

When building a view of a masked structured array, using a dtype with offsets, a ValueError exception is fired.

Note: With an array of type np.array instead of np.ma.MaskedArray, all runs fine.

Reproducing code example:

import numpy as np
x = np.array([('Rex', 9, 81.0), ('Fido', 3, 27.0)], dtype=[('name', 'U10'), ('age', 'i4'), ('weight', 'f4')])
age_dtype, age_offset = x.dtype.fields['age']
newdt = np.dtype({ 'names': ['age'], 'formats': [age_dtype], 'offsets': [age_offset], 'itemsize': x.dtype.itemsize })
# this works for now; it gives a view of x with column 'age' only
x.view(newdt)
# now converting x to a masked array
x = x.view(np.ma.MaskedArray)
# Oops!
x.view(newdt)

Error message:

Traceback (most recent call last):
  File "/home/etienne/sakura/.venv/lib/python3.5/site-packages/numpy/ma/core.py", line 3130, in view
    if issubclass(dtype, ndarray):
TypeError: issubclass() arg 1 must be a class

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/etienne/sakura/.venv/lib/python3.5/site-packages/numpy/ma/core.py", line 3136, in view
    output = ndarray.view(self, dtype)
  File "/home/etienne/sakura/.venv/lib/python3.5/site-packages/numpy/ma/core.py", line 3357, in dtype
    self._mask.shape = self.shape
ValueError: cannot reshape array of size 6 into shape (2,)

Numpy/Python version information:

>>> print(sys.version)
3.5.2 (default, Nov 23 2017, 16:37:01) 
[GCC 5.4.0 20160609]
>>> print(np.__version__)
1.15.0
>>> 
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

2 participants