From 7434423a3cba5c424436914c169072e7e6ad0031 Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 27 Jun 2023 10:37:08 -0700 Subject: [PATCH 1/2] REF: dedup Manager method, remove Manager.quantile axis kwd --- pandas/core/frame.py | 2 +- pandas/core/internals/array_manager.py | 8 -------- pandas/core/internals/base.py | 6 ++++++ pandas/core/internals/blocks.py | 4 ---- pandas/core/internals/managers.py | 6 ------ 5 files changed, 7 insertions(+), 19 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 3dac13df6b670..746c555edc989 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -11502,7 +11502,7 @@ def quantile( f"Invalid method: {method}. Method must be in {valid_method}." ) if method == "single": - res = data._mgr.quantile(qs=q, axis=1, interpolation=interpolation) + res = data._mgr.quantile(qs=q, interpolation=interpolation) elif method == "table": valid_interpolation = {"nearest", "lower", "higher"} if interpolation not in valid_interpolation: diff --git a/pandas/core/internals/array_manager.py b/pandas/core/internals/array_manager.py index 80bddb586fc53..f939ce469aab4 100644 --- a/pandas/core/internals/array_manager.py +++ b/pandas/core/internals/array_manager.py @@ -324,12 +324,6 @@ def diff(self, n: int) -> Self: assert self.ndim == 2 # caller ensures return self.apply(algos.diff, n=n) - def shift(self, periods: int, fill_value) -> Self: - if fill_value is lib.no_default: - fill_value = None - - return self.apply_with_block("shift", periods=periods, fill_value=fill_value) - def astype(self, dtype, copy: bool | None = False, errors: str = "raise") -> Self: if copy is None: copy = True @@ -930,12 +924,10 @@ def quantile( self, *, qs: Index, # with dtype float64 - axis: AxisInt = 0, transposed: bool = False, interpolation: QuantileInterpolation = "linear", ) -> ArrayManager: arrs = [ensure_block_shape(x, 2) for x in self.arrays] - assert axis == 1 new_arrs = [ quantile_compat(x, np.asarray(qs._values), interpolation) for x in arrs ] diff --git a/pandas/core/internals/base.py b/pandas/core/internals/base.py index 14aa2cc2716b9..bd5792ef34f6a 100644 --- a/pandas/core/internals/base.py +++ b/pandas/core/internals/base.py @@ -269,6 +269,12 @@ def pad_or_backfill(self, inplace: bool, **kwargs) -> Self: using_cow=using_copy_on_write(), ) + def shift(self, periods: int, fill_value) -> Self: + if fill_value is lib.no_default: + fill_value = None + + return self.apply_with_block("shift", periods=periods, fill_value=fill_value) + # -------------------------------------------------------------------- # Consolidation: No-ops for all but BlockManager diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index adfe11e83cdcc..832e1560ae55e 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -1511,7 +1511,6 @@ def quantile( self, qs: Index, # with dtype float64 interpolation: QuantileInterpolation = "linear", - axis: AxisInt = 0, ) -> Block: """ compute the quantiles of the @@ -1522,8 +1521,6 @@ def quantile( The quantiles to be computed in float64. interpolation : str, default 'linear' Type of interpolation. - axis : int, default 0 - Axis to compute. Returns ------- @@ -1531,7 +1528,6 @@ def quantile( """ # We should always have ndim == 2 because Series dispatches to DataFrame assert self.ndim == 2 - assert axis == 1 # only ever called this way assert is_list_like(qs) # caller is responsible for this result = quantile_compat(self.values, np.asarray(qs._values), interpolation) diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index f4c8b101d9f12..4b674d40a7ae6 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -378,12 +378,6 @@ def diff(self, n: int) -> Self: # only reached with self.ndim == 2 return self.apply("diff", n=n) - def shift(self, periods: int, fill_value) -> Self: - if fill_value is lib.no_default: - fill_value = None - - return self.apply("shift", periods=periods, fill_value=fill_value) - def astype(self, dtype, copy: bool | None = False, errors: str = "raise") -> Self: if copy is None: if using_copy_on_write(): From 0eb0e1a7d59a43744fe30e03485d5c024d27b2dd Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 27 Jun 2023 10:38:05 -0700 Subject: [PATCH 2/2] remove unused kwd --- pandas/core/internals/managers.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index 4b674d40a7ae6..dc08f719ffa5f 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -1457,7 +1457,6 @@ def quantile( self, *, qs: Index, # with dtype float 64 - axis: AxisInt = 0, interpolation: QuantileInterpolation = "linear", ) -> Self: """ @@ -1467,9 +1466,6 @@ def quantile( Parameters ---------- - axis: reduction axis, default 0 - consolidate: bool, default True. Join together blocks having same - dtype interpolation : type of interpolation, default 'linear' qs : list of the quantiles to be computed @@ -1481,14 +1477,12 @@ def quantile( # simplify some of the code here and in the blocks assert self.ndim >= 2 assert is_list_like(qs) # caller is responsible for this - assert axis == 1 # only ever called this way new_axes = list(self.axes) new_axes[1] = Index(qs, dtype=np.float64) blocks = [ - blk.quantile(axis=axis, qs=qs, interpolation=interpolation) - for blk in self.blocks + blk.quantile(qs=qs, interpolation=interpolation) for blk in self.blocks ] return type(self)(blocks, new_axes)