@@ -1447,8 +1447,18 @@ def quantile(self, qs, interpolation='linear', axis=0):
1447
1447
-------
1448
1448
Block
1449
1449
"""
1450
- values = self .get_values ()
1451
- values , _ = self ._try_coerce_args (values , values )
1450
+ if self .is_datetimetz :
1451
+ # We need to operate on i8 values for datetimetz
1452
+ # but `Block.get_values()` returns an ndarray of objects
1453
+ # right now.
1454
+ values = self .values .asi8
1455
+
1456
+ # Usual shape inconsistencies for ExtensionBlocks
1457
+ if self .ndim > 1 :
1458
+ values = values [None , :]
1459
+ else :
1460
+ values = self .get_values ()
1461
+ values , _ = self ._try_coerce_args (values , values )
1452
1462
1453
1463
is_empty = values .shape [axis ] == 0
1454
1464
orig_scalar = not is_list_like (qs )
@@ -2480,40 +2490,6 @@ def setitem(self, indexer, value):
2480
2490
klass = ObjectBlock ,)
2481
2491
return newb .setitem (indexer , value )
2482
2492
2483
- def quantile (self , qs , interpolation = 'linear' , axis = 0 , axes = None ):
2484
- # TODO: Add quantile as a reduction method.
2485
- # We can't just use Block.quantile, as that converts the DTA
2486
- # to an ndarray[object] via get_values.
2487
- # This method
2488
- # 1. Convert DatetimeTZBlock -> DatetimeBlock
2489
- # 2. Perform the op via Block.quantile
2490
- # 3. Converts back to tz-aware
2491
- # Alternatively, we could special case the call to `get_values`
2492
- # in Block.quantile for DatetimeTZ.
2493
-
2494
- new_values = np .asarray (self .values , dtype = _NS_DTYPE )
2495
- if self .ndim == 2 :
2496
- new_values = new_values [None , :]
2497
-
2498
- new_block = DatetimeBlock (new_values , placement = self .mgr_locs )
2499
-
2500
- ax , naive = new_block .quantile (qs , interpolation = interpolation ,
2501
- axis = axis , axes = axes )
2502
-
2503
- ndim = getattr (naive , 'ndim' , None ) or 0
2504
- if ndim == 0 :
2505
- return ax , self .make_block_scalar (
2506
- tslibs .Timestamp (naive .values .value , tz = self .values .tz )
2507
- )
2508
- else :
2509
- naive = naive .values .ravel ()
2510
-
2511
- result = DatetimeArray (naive , dtype = self .values .dtype )
2512
-
2513
- return ax , make_block (result ,
2514
- placement = np .arange (len (result )),
2515
- ndim = ndim )
2516
-
2517
2493
2518
2494
class TimeDeltaBlock (DatetimeLikeBlockMixin , IntBlock ):
2519
2495
__slots__ = ()
0 commit comments