31
31
is_extension_array_dtype ,
32
32
is_list_like ,
33
33
)
34
- from pandas .core .dtypes .concat import concat_compat
35
34
from pandas .core .dtypes .dtypes import ExtensionDtype
36
35
from pandas .core .dtypes .generic import ABCDataFrame , ABCPandasArray , ABCSeries
37
36
from pandas .core .dtypes .missing import array_equals , isna
40
39
from pandas .core .arrays .sparse import SparseDtype
41
40
from pandas .core .construction import extract_array
42
41
from pandas .core .indexers import maybe_convert_indices
43
- from pandas .core .indexes .api import Index , ensure_index
42
+ from pandas .core .indexes .api import Float64Index , Index , ensure_index
44
43
from pandas .core .internals .base import DataManager
45
44
from pandas .core .internals .blocks import (
46
45
Block ,
@@ -441,11 +440,11 @@ def apply(
441
440
442
441
def quantile (
443
442
self ,
443
+ * ,
444
+ qs : Float64Index ,
444
445
axis : int = 0 ,
445
446
transposed : bool = False ,
446
447
interpolation = "linear" ,
447
- qs = None ,
448
- numeric_only = None ,
449
448
) -> BlockManager :
450
449
"""
451
450
Iterate over blocks applying quantile reduction.
@@ -460,8 +459,7 @@ def quantile(
460
459
transposed: bool, default False
461
460
we are holding transposed data
462
461
interpolation : type of interpolation, default 'linear'
463
- qs : a scalar or list of the quantiles to be computed
464
- numeric_only : ignored
462
+ qs : list of the quantiles to be computed
465
463
466
464
Returns
467
465
-------
@@ -470,73 +468,25 @@ def quantile(
470
468
# Series dispatches to DataFrame for quantile, which allows us to
471
469
# simplify some of the code here and in the blocks
472
470
assert self .ndim >= 2
471
+ assert is_list_like (qs ) # caller is responsible for this
472
+ assert axis == 1 # only ever called this way
473
473
474
- def get_axe (block , qs , axes ):
475
- # Because Series dispatches to DataFrame, we will always have
476
- # block.ndim == 2
477
- from pandas import Float64Index
478
-
479
- if is_list_like (qs ):
480
- ax = Float64Index (qs )
481
- else :
482
- ax = axes [0 ]
483
- return ax
484
-
485
- axes , blocks = [], []
486
- for b in self .blocks :
487
- block = b .quantile (axis = axis , qs = qs , interpolation = interpolation )
488
-
489
- axe = get_axe (b , qs , axes = self .axes )
490
-
491
- axes .append (axe )
492
- blocks .append (block )
493
-
494
- # note that some DatetimeTZ, Categorical are always ndim==1
495
- ndim = {b .ndim for b in blocks }
496
- assert 0 not in ndim , ndim
497
-
498
- if 2 in ndim :
499
-
500
- new_axes = list (self .axes )
501
-
502
- # multiple blocks that are reduced
503
- if len (blocks ) > 1 :
504
- new_axes [1 ] = axes [0 ]
505
-
506
- # reset the placement to the original
507
- for b , sb in zip (blocks , self .blocks ):
508
- b .mgr_locs = sb .mgr_locs
509
-
510
- else :
511
- new_axes [axis ] = Index (np .concatenate ([ax ._values for ax in axes ]))
512
-
513
- if transposed :
514
- new_axes = new_axes [::- 1 ]
515
- blocks = [
516
- b .make_block (b .values .T , placement = np .arange (b .shape [1 ]))
517
- for b in blocks
518
- ]
519
-
520
- return type (self )(blocks , new_axes )
521
-
522
- # single block, i.e. ndim == {1}
523
- values = concat_compat ([b .values for b in blocks ])
524
-
525
- # compute the orderings of our original data
526
- if len (self .blocks ) > 1 :
474
+ new_axes = list (self .axes )
475
+ new_axes [1 ] = Float64Index (qs )
527
476
528
- indexer = np .empty (len (self .axes [0 ]), dtype = np .intp )
529
- i = 0
530
- for b in self .blocks :
531
- for j in b .mgr_locs :
532
- indexer [j ] = i
533
- i = i + 1
477
+ blocks = [
478
+ blk .quantile (axis = axis , qs = qs , interpolation = interpolation )
479
+ for blk in self .blocks
480
+ ]
534
481
535
- values = values .take (indexer )
482
+ if transposed :
483
+ new_axes = new_axes [::- 1 ]
484
+ blocks = [
485
+ b .make_block (b .values .T , placement = np .arange (b .shape [1 ]))
486
+ for b in blocks
487
+ ]
536
488
537
- return SingleBlockManager (
538
- make_block (values , ndim = 1 , placement = np .arange (len (values ))), axes [0 ]
539
- )
489
+ return type (self )(blocks , new_axes )
540
490
541
491
def isna (self , func ) -> BlockManager :
542
492
return self .apply ("apply" , func = func )
0 commit comments