8000 Error when equating a masked and non-masked structured array · Issue #3840 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
Error when equating a masked and non-masked structured array #3840
Closed
@astrofrog

Description

@astrofrog

I see the following error with the latest version of Numpy (1.8.0rc1):

In [3]: x = np.ma.MaskedArray([(2,),(2,)], dtype = [('a', '<i8')])

In [4]: y = np.array([(2,), (2,)], dtype=[('a', '<i8')])

In [5]: x == y
Old (outdated) traceback
Out[5]: ---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-5-73b2790c1e5e> in <module>()
----> 1 x == y

/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/IPython/core/displayhook.py in __call__(self, result)
    245             self.start_displayhook()
    246             self.write_output_prompt()
--> 247             format_dict, md_dict = self.compute_format_data(result)
    248             self.write_format_data(format_dict, md_dict)
    249             self.update_user_ns(result)

/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/IPython/core/displayhook.py in compute_format_data(self, result)
    155 
    156         """
--> 157         return self.shell.display_formatter.format(result)
    158 
    159     def write_format_data(self, format_dict, md_dict=None):

/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/IPython/core/formatters.py in format(self, obj, include, exclude)
    150             md = None
    151             try:
--> 152                 data = formatter(obj)
    153             except:
    154                 # FIXME: log the exception

/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/IPython/core/formatters.py in __call__(self, obj)
    478                 type_pprinters=self.type_printers,
    479                 deferred_pprinters=self.deferred_printers)
--> 480             printer.pretty(obj)
    481             printer.flush()
    482             return stream.getvalue()

/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/IPython/lib/pretty.py in pretty(self, obj)
    361                             if isinstance(meth, collections.Callable):
    362                                 return meth(obj, self, cycle)
--> 363             return _default_pprint(obj, self, cycle)
    364         finally:
    365             self.end_group()

/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/IPython/lib/pretty.py in _default_pprint(obj, p, cycle)
    481     if getattr(klass, '__repr__', None) not in _baseclass_reprs:
    482         # A user-provided repr.
--> 483         p.text(repr(obj))
    484         return
    485     p.begin_group(1, '<')

/Users/tom/Library/Python/3.3/lib/python/site-packages/numpy/ma/core.py in __repr__(self)
   3601         name = repr(self._data).split('(')[0]
   3602         parameters = dict(name=name, nlen=" " * len(name),
-> 3603                            data=str(self), mask=str(self._mask),
   3604                            fill=str(self.fill_value), dtype=str(self.dtype))
   3605         if self.dtype.names:

/Users/tom/Library/Python/3.3/lib/python/site-packages/numpy/ma/core.py in __str__(self)
   3585                 if names is None:
   3586                     res = self._data.astype("O")
-> 3587                     res[m] = f
   3588                 else:
   3589                     rdtype = _recursive_make_descr(self.dtype, "O")

IndexError: arrays used as indices must be of integer (or boolean) type

I think the correct behavior internally should be equivalent to:

In [6]: x == np.ma.MaskedArray(y)
Out[6]: 
masked_array(data = [True True],
             mask = [False False],
       fill_value = True)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0