8000 Inconsistent behavior using numpy.r_ with a masked array · Issue #9233 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

Inconsistent behavior using numpy.r_ with a masked array #9233

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
wilywampa opened this issue Jun 9, 2017 · 6 comments
Closed

Inconsistent behavior using numpy.r_ with a masked array #9233

wilywampa opened this issue Jun 9, 2017 · 6 comments
Labels
component: numpy.ma masked arrays

Comments

@wilywampa
Copy link

When using numpy.r_ to, for example, append a value to an array, the operation fails with a ValueError if the element to be appended is masked. The behavior should be to add another masked value to the end of the array. See below where the exact same use of r_ fails when using a masked element.

Python 3.6.0 (default, Dec 24 2016, 08:02:28)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.__version__
'1.14.0.dev0+18f69fd'
>>> x = np.ma.arange(3)
>>> np.r_[x, x[-1]]
masked_array(data = [0 1 2 2],
             mask = False,
       fill_value = 999999)

>>> x[-1] = np.ma.masked
>>> np.r_[x, x[-1]]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jniehus/Documents/dev/numpy_test_env/lib/python3.6/site-packages/numpy-1.14.0.dev0+18f69fd-py3.6-macosx-10.10-x86_64.egg/numpy/lib/index_tricks.py", line 340, in __getitem__
    res = self.concatenate(tuple(objs), axis=axis)
ValueError: all the input arrays must have same number of dimensions
@eric-wieser
Copy link
Member

There is a np.ma.r_ to work around this issue. The underlying problem is that np.concatenate does not work on masked arrays, and np.ma.concatenate must be used.

@wilywampa
Copy link
Author

There is a np.ma.r_ to work around this issue.

Is there? I just get an AttributeError.

@eric-wieser
Copy link
Member
eric-wieser commented Jun 12, 2017

Apologies, it's called np.ma.mr_

@wilywampa
Copy link
Author

np.ma.mr_ raises the same exception when used as in my example.

@eric-wieser
Copy link
Member
eric-wieser commented Jun 14, 2017

Ah, my apologies for misdiagnosing. A similar failure that doesn't involve masked arrays:

>>> np.r_[[1, 2], 3]
array([1, 2, 3])
>>> np.r_[[1, 2], np.array(3)]
ValueError: all the input arrays must have same number of dimensions

So there are potentially two problems here - r_ does not handle 0d arrays in the same way as scalars, and np.ma.masked is a 0d array, not a scalar

@eric-wieser
Copy link
Member

So this is caused by #7588

@eric-wieser eric-wieser added the component: numpy.ma masked arrays label Jun 30, 2017
eric-wieser added a commit to eric-wieser/numpy that referenced this issue Dec 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: numpy.ma masked arrays
Projects
None yet
Development

No branches or pull requests

2 participants
0