Return a class method wrapper around a basic array method. Creates a class method which returns a masked array, where the new ``_data`` array is the output of the corresponding basic method called on the original ``_data``. If `onmask` is True, the new mask is the output of th
(funcname, onmask=True)
| 2613 | |
| 2614 | |
| 2615 | def _arraymethod(funcname, onmask=True): |
| 2616 | """ |
| 2617 | Return a class method wrapper around a basic array method. |
| 2618 | |
| 2619 | Creates a class method which returns a masked array, where the new |
| 2620 | ``_data`` array is the output of the corresponding basic method called |
| 2621 | on the original ``_data``. |
| 2622 | |
| 2623 | If `onmask` is True, the new mask is the output of the method called |
| 2624 | on the initial mask. Otherwise, the new mask is just a reference |
| 2625 | to the initial mask. |
| 2626 | |
| 2627 | Parameters |
| 2628 | ---------- |
| 2629 | funcname : str |
| 2630 | Name of the function to apply on data. |
| 2631 | onmask : bool |
| 2632 | Whether the mask must be processed also (True) or left |
| 2633 | alone (False). Default is True. Make available as `_onmask` |
| 2634 | attribute. |
| 2635 | |
| 2636 | Returns |
| 2637 | ------- |
| 2638 | method : instancemethod |
| 2639 | Class method wrapper of the specified basic array method. |
| 2640 | |
| 2641 | """ |
| 2642 | def wrapped_method(self, *args, **params): |
| 2643 | result = getattr(self._data, funcname)(*args, **params) |
| 2644 | result = result.view(type(self)) |
| 2645 | result._update_from(self) |
| 2646 | mask = self._mask |
| 2647 | if not onmask: |
| 2648 | result.__setmask__(mask) |
| 2649 | elif mask is not nomask: |
| 2650 | # __setmask__ makes a copy, which we don't want |
| 2651 | result._mask = getattr(mask, funcname)(*args, **params) |
| 2652 | return result |
| 2653 | methdoc = getattr(ndarray, funcname, None) or getattr(np, funcname, None) |
| 2654 | if methdoc is not None: |
| 2655 | wrapped_method.__doc__ = methdoc.__doc__ |
| 2656 | wrapped_method.__name__ = funcname |
| 2657 | return wrapped_method |
| 2658 | |
| 2659 | |
| 2660 | class MaskedIterator: |
no outgoing calls
no test coverage detected
searching dependent graphs…