Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

cannot access masked array rows with np.object dtype (Fixes #2432) #2747

Merged
merged 2 commits into from

3 participants

@mdboom

In the astropy project we've run into bug #2432. (See astropy/astropy#465).

This bug is made more prominent the recent commit 7caac2e, since mvoid arrays are created in all cases, not just when there are masked elements.

The fix here is just to use the Numpy array constructor instead of itemwise assignment, which does handle object fields correctly.

Hope this makes sense -- I can't say I'm an expert on the masked array code.

@mdboom mdboom Fixes #2432. Rather than creating a new data array and assigning to i…
…t (which doesn't work when it is a recarray containing object fields), just create a copy with the np.array constructor.
0196aed
@mdboom mdboom referenced this pull request in astropy/astropy
Closed

Failing test_from_scratch_example in vo_test.py #465

@njsmith
Owner

Needs a test.

@mdboom

Test added.

@astrofrog

@njsmith - would it be possible for this PR to be merged in the near future? The reason I ask is that we are finalizing issues for a release of astropy (http://www.astropy.org), and it would be useful to know if this fix will be included, or whether we will have to add a workaround to our code. Thanks!

@njsmith
Owner

Looks fine to me -- anyone more familiar with the masked array code want to chime in?

Also if I'm reading the history here right, you're only worried about this for 1.8, right, and 1.7 is fine as-is?

@astrofrog

@njsmith - it depends whether 7caac2e will make 1.7, or if it will only be included in 1.8. If 7caac2e is not in 1.7, then yes we are only worried for 1.8.

@njsmith
Owner

7caac2e is #483, right? That PR isn't backported to 1.7, so I guess this one shouldn't be either.

And if we're not backporting to 1.7 then I'm less worried about getting review on this since 1.8 will have its own rounds of RCs, so, merging.

@njsmith njsmith merged commit 686bcfd into numpy:master
@astrofrog

@njsmith - yes, that's the right pull request. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 15, 2012
  1. @mdboom

    Fixes #2432. Rather than creating a new data array and assigning to i…

    mdboom authored
    …t (which doesn't work when it is a recarray containing object fields), just create a copy with the np.array constructor.
Commits on Dec 3, 2012
  1. @mdboom

    Add a test

    mdboom authored
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 2 deletions.
  1. +1 −2  numpy/ma/core.py
  2. +12 −0 numpy/ma/tests/test_mrecords.py
View
3  numpy/ma/core.py
@@ -5509,8 +5509,7 @@ class mvoid(MaskedArray):
#
def __new__(self, data, mask=nomask, dtype=None, fill_value=None):
dtype = dtype or data.dtype
- _data = ndarray((), dtype=dtype)
- _data[()] = data
+ _data = np.array(data, dtype=dtype)
_data = _data.view(self)
if mask is not nomask:
if isinstance(mask, np.void):
View
12 numpy/ma/tests/test_mrecords.py
@@ -502,6 +502,18 @@ def test_addfield(self):
assert_equal(mrec.f3, d)
assert_equal(mrec.f3._mask, m)
+
+def test_record_array_with_object_field():
+ """
+ Trac #1839
+ """
+ y = ma.masked_array(
+ [(1,'2'), (3, '4')],
+ mask=[(0, 0), (0, 1)],
+ dtype=[('a', int), ('b', np.object)])
+ x = y[1]
+
+
###############################################################################
#------------------------------------------------------------------------------
if __name__ == "__main__":
Something went wrong with that request. Please try again.