Parameters ---------- result : array-like or tuple[array-like] mask : array-like bool
(
self, result: np.ndarray | tuple[np.ndarray, np.ndarray], mask: np.ndarray
)
| 975 | return BooleanArray(result, mask, copy=False) |
| 976 | |
| 977 | def _maybe_mask_result( |
| 978 | self, result: np.ndarray | tuple[np.ndarray, np.ndarray], mask: np.ndarray |
| 979 | ): |
| 980 | """ |
| 981 | Parameters |
| 982 | ---------- |
| 983 | result : array-like or tuple[array-like] |
| 984 | mask : array-like bool |
| 985 | """ |
| 986 | if isinstance(result, tuple): |
| 987 | # i.e. divmod |
| 988 | div, mod = result |
| 989 | return ( |
| 990 | self._maybe_mask_result(div, mask), |
| 991 | self._maybe_mask_result(mod, mask), |
| 992 | ) |
| 993 | |
| 994 | if result.dtype.kind == "f": |
| 995 | from pandas.core.arrays import FloatingArray |
| 996 | |
| 997 | if is_nan_na(): |
| 998 | mask[np.isnan(result)] = True |
| 999 | |
| 1000 | return FloatingArray(result, mask, copy=False) |
| 1001 | |
| 1002 | elif result.dtype.kind == "b": |
| 1003 | from pandas.core.arrays import BooleanArray |
| 1004 | |
| 1005 | return BooleanArray(result, mask, copy=False) |
| 1006 | |
| 1007 | elif lib.is_np_dtype(result.dtype, "m") and is_supported_dtype(result.dtype): |
| 1008 | # e.g. test_numeric_arr_mul_tdscalar_numexpr_path |
| 1009 | from pandas.core.arrays import TimedeltaArray |
| 1010 | |
| 1011 | unit = np.datetime_data(result.dtype)[0] |
| 1012 | result[mask] = np.timedelta64("NaT", unit) # type: ignore[call-overload] |
| 1013 | |
| 1014 | if not isinstance(result, TimedeltaArray): |
| 1015 | return TimedeltaArray._simple_new(result, dtype=result.dtype) |
| 1016 | |
| 1017 | return result |
| 1018 | |
| 1019 | elif result.dtype.kind in "iu": |
| 1020 | from pandas.core.arrays import IntegerArray |
| 1021 | |
| 1022 | return IntegerArray(result, mask, copy=False) |
| 1023 | |
| 1024 | elif result.dtype == object: |
| 1025 | result[mask] = self.dtype.na_value |
| 1026 | return result |
| 1027 | else: |
| 1028 | result[mask] = np.nan |
| 1029 | return result |
| 1030 | |
| 1031 | def isna(self) -> np.ndarray: |
| 1032 | return self._mask.copy() |
no test coverage detected