@@ -1526,18 +1526,7 @@ def quantile(self, qs, interpolation="linear", axis=0):
1526
1526
# We should always have ndim == 2 becase Series dispatches to DataFrame
1527
1527
assert self .ndim == 2
1528
1528
1529
- if self .is_datetimetz :
1530
- # TODO: cleanup this special case.
1531
- # We need to operate on i8 values for datetimetz
1532
- # but `Block.get_values()` returns an ndarray of objects
1533
- # right now. We need an API for "values to do numeric-like ops on"
1534
- values = self .values .view ("M8[ns]" )
1535
-
1536
- # TODO: NonConsolidatableMixin shape
1537
- # Usual shape inconsistencies for ExtensionBlocks
1538
- values = values [None , :]
1539
- else :
1540
- values = self .get_values ()
1529
+ values = self .get_values ()
1541
1530
1542
1531
is_empty = values .shape [axis ] == 0
1543
1532
orig_scalar = not is_list_like (qs )
@@ -1576,7 +1565,6 @@ def quantile(self, qs, interpolation="linear", axis=0):
1576
1565
result = lib .item_from_zerodim (result )
1577
1566
1578
1567
ndim = getattr (result , "ndim" , None ) or 0
1579
- result = self ._try_coerce_result (result )
1580
1568
return make_block (result , placement = np .arange (len (result )), ndim = ndim )
1581
1569
1582
1570
def _replace_coerce (
@@ -2477,21 +2465,9 @@ def _try_coerce_result(self, result):
2477
2465
result = self ._holder ._from_sequence (
2478
2466
result .astype (np .int64 ), freq = None , dtype = self .values .dtype
2479
2467
)
2480
- elif result .dtype == "M8[ns]" :
2481
- # otherwise we get here via quantile and already have M8[ns]
2482
- result = self ._holder ._simple_new (
2483
- result , freq = None , dtype = self .values .dtype
2484
- )
2485
2468
2486
- elif isinstance (result , np .datetime64 ):
2487
- # also for post-quantile
2488
- result = self ._box_func (result )
2489
2469
return result
2490
2470
2491
- @property
2492
- def _box_func (self ):
2493
- return lambda x : tslibs .Timestamp (x , tz = self .dtype .tz )
2494
-
2495
2471
def diff (self , n , axis = 0 ):
2496
2472
"""1st discrete difference
2497
2473
@@ -2564,6 +2540,19 @@ def equals(self, other):
2564
2540
return False
2565
2541
return (self .values .view ("i8" ) == other .values .view ("i8" )).all ()
2566
2542
2543
+ def quantile (self , qs , interpolation = "linear" , axis = 0 ):
2544
+ naive = self .values .view ("M8[ns]" )
2545
+
2546
+ # kludge for 2D block with 1D values
2547
+ naive = naive .reshape (self .shape )
2548
+
2549
+ blk = self .make_block (naive )
2550
+ res_blk = blk .quantile (qs , interpolation = interpolation , axis = axis )
2551
+
2552
+ # ravel is kludge for 2D block with 1D values, assumes column-like
2553
+ aware = self ._holder (res_blk .values .ravel (), dtype = self .dtype )
2554
+ return self .make_block_same_class (aware , ndim = res_blk .ndim )
2555
+
2567
2556
2568
2557
class TimeDeltaBlock (DatetimeLikeBlockMixin , IntBlock ):
2569
2558
__slots__ = ()
0 commit comments