MCPcopy Index your code
hub / github.com/numpy/numpy / mvoid

Class mvoid

numpy/ma/core.py:6544–6677  ·  view source on GitHub ↗

Fake a 'void' object to use for masked array with structured dtypes.

Source from the content-addressed store, hash-verified

6542
6543
6544class mvoid(MaskedArray):
6545 """
6546 Fake a 'void' object to use for masked array with structured dtypes.
6547 """
6548
6549 def __new__(cls, data, mask=nomask, dtype=None, fill_value=None,
6550 hardmask=False, copy=False, subok=True):
6551 copy = None if not copy else True
6552 _data = np.array(data, copy=copy, subok=subok, dtype=dtype)
6553 _data = _data.view(cls)
6554 _data._hardmask = hardmask
6555 if mask is not nomask:
6556 if isinstance(mask, np.void):
6557 _data._mask = mask
6558 else:
6559 try:
6560 # Mask is already a 0D array
6561 _data._mask = np.void(mask)
6562 except TypeError:
6563 # Transform the mask to a void
6564 mdtype = make_mask_descr(dtype)
6565 _data._mask = np.array(mask, dtype=mdtype)[()]
6566 if fill_value is not None:
6567 _data.fill_value = fill_value
6568 return _data
6569
6570 @property
6571 def _data(self):
6572 # Make sure that the _data part is a np.void
6573 return super()._data[()]
6574
6575 def __getitem__(self, indx):
6576 """
6577 Get the index.
6578
6579 """
6580 m = self._mask
6581 if isinstance(m[indx], ndarray):
6582 # Can happen when indx is a multi-dimensional field:
6583 # A = ma.masked_array(data=[([0,1],)], mask=[([True,
6584 # False],)], dtype=[("A", ">i2", (2,))])
6585 # x = A[0]; y = x["A"]; then y.mask["A"].size==2
6586 # and we can not say masked/unmasked.
6587 # The result is no longer mvoid!
6588 # See also issue #6724.
6589 return masked_array(
6590 data=self._data[indx], mask=m[indx],
6591 fill_value=self._fill_value[indx],
6592 hard_mask=self._hardmask)
6593 if m is not nomask and m[indx]:
6594 return masked
6595 return self._data[indx]
6596
6597 def __setitem__(self, indx, value):
6598 self._data[indx] = value
6599 if self._hardmask:
6600 self._mask[indx] |= getattr(value, "_mask", False)
6601 else:

Callers 6

test_void0dMethod · 0.90
__getitem__Method · 0.85
__next__Method · 0.85
__getitem__Method · 0.85

Calls

no outgoing calls

Tested by 3

test_void0dMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…