@@ -99,6 +99,12 @@ class NDArrayBackedExtensionArray(NDArrayBacked, ExtensionArray):
99
99
100
100
_ndarray : np .ndarray
101
101
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
+
102
108
def _box_func (self , x ):
103
109
"""
104
110
Wrap numpy type in our dtype.type if necessary.
@@ -463,18 +469,25 @@ def _quantile(
463
469
mask = np .atleast_2d (mask )
464
470
465
471
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
468
473
469
474
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 )
472
477
if self .ndim == 1 :
473
478
assert result .shape == (1 , len (qs )), result .shape
474
479
result = result [0 ]
475
480
476
481
return result
477
482
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
+
478
491
# ------------------------------------------------------------------------
479
492
# numpy-like methods
480
493
0 commit comments