3131 is_extension_array_dtype ,
3232 is_list_like ,
3333)
34- from pandas .core .dtypes .concat import concat_compat
3534from pandas .core .dtypes .dtypes import ExtensionDtype
3635from pandas .core .dtypes .generic import ABCDataFrame , ABCPandasArray , ABCSeries
3736from pandas .core .dtypes .missing import array_equals , isna
4039from pandas .core .arrays .sparse import SparseDtype
4140from pandas .core .construction import extract_array
4241from 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
4443from pandas .core .internals .base import DataManager
4544from pandas .core .internals .blocks import (
4645 Block ,
@@ -441,11 +440,11 @@ def apply(
441440
442441 def quantile (
443442 self ,
443+ * ,
444+ qs : Float64Index ,
444445 axis : int = 0 ,
445446 transposed : bool = False ,
446447 interpolation = "linear" ,
447- qs = None ,
448- numeric_only = None ,
449448 ) -> BlockManager :
450449 """
451450 Iterate over blocks applying quantile reduction.
@@ -460,8 +459,7 @@ def quantile(
460459 transposed: bool, default False
461460 we are holding transposed data
462461 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
465463
466464 Returns
467465 -------
@@ -470,73 +468,25 @@ def quantile(
470468 # Series dispatches to DataFrame for quantile, which allows us to
471469 # simplify some of the code here and in the blocks
472470 assert self .ndim >= 2
471+ assert is_list_like (qs ) # caller is responsible for this
472+ assert axis == 1 # only ever called this way
473473
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 )
527476
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+ ]
534481
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+ ]
536488
537- return SingleBlockManager (
538- make_block (values , ndim = 1 , placement = np .arange (len (values ))), axes [0 ]
539- )
489+ return type (self )(blocks , new_axes )
540490
541491 def isna (self , func ) -> BlockManager :
542492 return self .apply ("apply" , func = func )
0 commit comments