x.__setitem__(i, y) <==> x[i]=y Set item described by index. If value is masked, masks those locations.
(self, indx, value)
| 3345 | # correct warnings (as is typical also in masked calculations). |
| 3346 | @np.errstate(over='ignore', invalid='ignore') |
| 3347 | def __setitem__(self, indx, value): |
| 3348 | """ |
| 3349 | x.__setitem__(i, y) <==> x[i]=y |
| 3350 | |
| 3351 | Set item described by index. If value is masked, masks those |
| 3352 | locations. |
| 3353 | |
| 3354 | """ |
| 3355 | if self is masked: |
| 3356 | raise MaskError('Cannot alter the masked element.') |
| 3357 | _data = self._data |
| 3358 | _mask = self._mask |
| 3359 | if isinstance(indx, str): |
| 3360 | _data[indx] = value |
| 3361 | if _mask is nomask: |
| 3362 | self._mask = _mask = make_mask_none(self.shape, self.dtype) |
| 3363 | _mask[indx] = getmask(value) |
| 3364 | return |
| 3365 | |
| 3366 | _dtype = _data.dtype |
| 3367 | |
| 3368 | if value is masked: |
| 3369 | # The mask wasn't set: create a full version. |
| 3370 | if _mask is nomask: |
| 3371 | _mask = self._mask = make_mask_none(self.shape, _dtype) |
| 3372 | # Now, set the mask to its value. |
| 3373 | if _dtype.names is not None: |
| 3374 | _mask[indx] = tuple([True] * len(_dtype.names)) |
| 3375 | else: |
| 3376 | _mask[indx] = True |
| 3377 | return |
| 3378 | |
| 3379 | # Get the _data part of the new value |
| 3380 | dval = getattr(value, '_data', value) |
| 3381 | # Get the _mask part of the new value |
| 3382 | mval = getmask(value) |
| 3383 | if _dtype.names is not None and mval is nomask: |
| 3384 | mval = tuple([False] * len(_dtype.names)) |
| 3385 | if _mask is nomask: |
| 3386 | # Set the data, then the mask |
| 3387 | _data[indx] = dval |
| 3388 | if mval is not nomask: |
| 3389 | _mask = self._mask = make_mask_none(self.shape, _dtype) |
| 3390 | _mask[indx] = mval |
| 3391 | elif not self._hardmask: |
| 3392 | # Set the data, then the mask |
| 3393 | if (isinstance(indx, masked_array) and |
| 3394 | not isinstance(value, masked_array)): |
| 3395 | _data[indx.data] = dval |
| 3396 | else: |
| 3397 | _data[indx] = dval |
| 3398 | _mask[indx] = mval |
| 3399 | elif hasattr(indx, 'dtype') and (indx.dtype == MaskType): |
| 3400 | indx = indx * umath.logical_not(_mask) |
| 3401 | _data[indx] = dval |
| 3402 | else: |
| 3403 | if _dtype.names is not None: |
| 3404 | err_msg = "Flexible 'hard' masks are not yet supported." |
nothing calls this directly
no test coverage detected