@@ -99,6 +99,12 @@ class NDArrayBackedExtensionArray(NDArrayBacked, ExtensionArray):
9999
100100 _ndarray : np .ndarray
101101
102+ # scalar used to denote NA value inside our self._ndarray, e.g. -1
103+ # for Categorical, iNaT for Period. Outside of object dtype,
104+ # self.isna() should be exactly locations in self._ndarray with
105+ # _internal_fill_value.
106+ _internal_fill_value : Any
107+
102108 def _box_func (self , x ):
103109 """
104110 Wrap numpy type in our dtype.type if necessary.
@@ -463,18 +469,25 @@ def _quantile(
463469 mask = np .atleast_2d (mask )
464470
465471 arr = np .atleast_2d (self ._ndarray )
466- # TODO: something NDArrayBacked-specific instead of _values_for_factorize[1]?
467- fill_value = self ._values_for_factorize ()[1 ]
472+ fill_value = self ._internal_fill_value
468473
469474 res_values = quantile_with_mask (arr , mask , fill_value , qs , interpolation )
470-
471- result = type ( self ). _from_factorized (res_values , self )
475+ res_values = self . _cast_quantile_result ( res_values )
476+ result = self . _from_backing_data (res_values )
472477 if self .ndim == 1 :
473478 assert result .shape == (1 , len (qs )), result .shape
474479 result = result [0 ]
475480
476481 return result
477482
483+ # TODO: see if we can share this with other dispatch-wrapping methods
484+ def _cast_quantile_result (self , res_values : np .ndarray ) -> np .ndarray :
485+ """
486+ Cast the result of quantile_with_mask to an appropriate dtype
487+ to pass to _from_backing_data in _quantile.
488+ """
489+ return res_values
490+
478491 # ------------------------------------------------------------------------
479492 # numpy-like methods
480493
0 commit comments