def _quantile( self: BaseMaskedArrayT, qs: npt.NDArray[np.float64], interpolation: str ) -> BaseMaskedArrayT: """ Dispatch to quantile_with_mask, needed because we do not have _from_factorized. Notes ----- We assume that all impacted cases are 1D-only. """ mask = np.atleast_2d(np.asarray(self.isna())) npvalues: np.ndarray = np.atleast_2d(np.asarray(self)) res = quantile_with_mask( npvalues, mask=mask, fill_value=self.dtype.na_value, qs=qs, interpolation=interpolation, ) assert res.ndim == 2 assert res.shape[0] == 1 res = res[0] try: out = type(self)._from_sequence(res, dtype=self.dtype) except TypeError: # GH#42626: not able to safely cast Int64 # for floating point output out = np.asarray(res, dtype=np.float64) return out
def _quantile(self, qs: npt.NDArray[np.float64], interpolation: str) -> BaseMaskedArray: """ Dispatch to quantile_with_mask, needed because we do not have _from_factorized. Notes ----- We assume that all impacted cases are 1D-only. """ res = quantile_with_mask( self._data, mask=self._mask, # TODO(GH#40932): na_value_for_dtype(self.dtype.numpy_dtype) # instead of np.nan fill_value=np.nan, qs=qs, interpolation=interpolation, ) if self._hasna: # Our result mask is all-False unless we are all-NA, in which # case it is all-True. if self.ndim == 2: # I think this should be out_mask=self.isna().all(axis=1) # but am holding off until we have tests raise NotImplementedError elif self.isna().all(): out_mask = np.ones(res.shape, dtype=bool) else: out_mask = np.zeros(res.shape, dtype=bool) else: out_mask = np.zeros(res.shape, dtype=bool) return self._maybe_mask_result(res, mask=out_mask)
def _quantile( self: NDArrayBackedExtensionArrayT, qs: npt.NDArray[np.float64], interpolation: str, ) -> NDArrayBackedExtensionArrayT: # TODO: disable for Categorical if not ordered? mask = np.asarray(self.isna()) arr = self._ndarray fill_value = self._internal_fill_value res_values = quantile_with_mask(arr, mask, fill_value, qs, interpolation) res_values = self._cast_quantile_result(res_values) return self._from_backing_data(res_values)
def _quantile( self: NDArrayBackedExtensionArrayT, qs: npt.NDArray[np.float64], interpolation: str, ) -> NDArrayBackedExtensionArrayT: # TODO: disable for Categorical if not ordered? # asarray needed for Sparse, see GH#24600 mask = np.asarray(self.isna()) mask = np.atleast_2d(mask) arr = np.atleast_2d(self._ndarray) # TODO: something NDArrayBacked-specific instead of _values_for_factorize[1]? fill_value = self._values_for_factorize()[1] res_values = quantile_with_mask(arr, mask, fill_value, qs, interpolation) result = type(self)._from_factorized(res_values, self) if self.ndim == 1: assert result.shape == (1, len(qs)), result.shape result = result[0] return result
def _quantile( self: NDArrayBackedExtensionArrayT, qs: npt.NDArray[np.float64], interpolation: str, ) -> NDArrayBackedExtensionArrayT: # TODO: disable for Categorical if not ordered? # asarray needed for Sparse, see GH#24600 mask = np.asarray(self.isna()) mask = np.atleast_2d(mask) arr = np.atleast_2d(self._ndarray) fill_value = self._internal_fill_value res_values = quantile_with_mask(arr, mask, fill_value, qs, interpolation) res_values = self._cast_quantile_result(res_values) result = self._from_backing_data(res_values) if self.ndim == 1: assert result.shape == (1, len(qs)), result.shape result = result[0] return result