Skip to content

Commit 3e6adac

Browse files
authored
REF: de-duplicate methods, remove unused kwd (#53886)
* REF: dedup Manager method, remove Manager.quantile axis kwd * remove unused kwd
1 parent 12b114b commit 3e6adac

File tree

5 files changed

+8
-26
lines changed

5 files changed

+8
-26
lines changed

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11502,7 +11502,7 @@ def quantile(
1150211502
f"Invalid method: {method}. Method must be in {valid_method}."
1150311503
)
1150411504
if method == "single":
11505-
res = data._mgr.quantile(qs=q, axis=1, interpolation=interpolation)
11505+
res = data._mgr.quantile(qs=q, interpolation=interpolation)
1150611506
elif method == "table":
1150711507
valid_interpolation = {"nearest", "lower", "higher"}
1150811508
if interpolation not in valid_interpolation:

pandas/core/internals/array_manager.py

-8
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,6 @@ def diff(self, n: int) -> Self:
324324
assert self.ndim == 2 # caller ensures
325325
return self.apply(algos.diff, n=n)
326326

327-
def shift(self, periods: int, fill_value) -> Self:
328-
if fill_value is lib.no_default:
329-
fill_value = None
330-
331-
return self.apply_with_block("shift", periods=periods, fill_value=fill_value)
332-
333327
def astype(self, dtype, copy: bool | None = False, errors: str = "raise") -> Self:
334328
if copy is None:
335329
copy = True
@@ -930,12 +924,10 @@ def quantile(
930924
self,
931925
*,
932926
qs: Index, # with dtype float64
933-
axis: AxisInt = 0,
934927
transposed: bool = False,
935928
interpolation: QuantileInterpolation = "linear",
936929
) -> ArrayManager:
937930
arrs = [ensure_block_shape(x, 2) for x in self.arrays]
938-
assert axis == 1
939931
new_arrs = [
940932
quantile_compat(x, np.asarray(qs._values), interpolation) for x in arrs
941933
]

pandas/core/internals/base.py

+6
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,12 @@ def pad_or_backfill(self, inplace: bool, **kwargs) -> Self:
269269
using_cow=using_copy_on_write(),
270270
)
271271

272+
def shift(self, periods: int, fill_value) -> Self:
273+
if fill_value is lib.no_default:
274+
fill_value = None
275+
276+
return self.apply_with_block("shift", periods=periods, fill_value=fill_value)
277+
272278
# --------------------------------------------------------------------
273279
# Consolidation: No-ops for all but BlockManager
274280

pandas/core/internals/blocks.py

-4
Original file line numberDiff line numberDiff line change
@@ -1511,7 +1511,6 @@ def quantile(
15111511
self,
15121512
qs: Index, # with dtype float64
15131513
interpolation: QuantileInterpolation = "linear",
1514-
axis: AxisInt = 0,
15151514
) -> Block:
15161515
"""
15171516
compute the quantiles of the
@@ -1522,16 +1521,13 @@ def quantile(
15221521
The quantiles to be computed in float64.
15231522
interpolation : str, default 'linear'
15241523
Type of interpolation.
1525-
axis : int, default 0
1526-
Axis to compute.
15271524
15281525
Returns
15291526
-------
15301527
Block
15311528
"""
15321529
# We should always have ndim == 2 because Series dispatches to DataFrame
15331530
assert self.ndim == 2
1534-
assert axis == 1 # only ever called this way
15351531
assert is_list_like(qs) # caller is responsible for this
15361532

15371533
result = quantile_compat(self.values, np.asarray(qs._values), interpolation)

pandas/core/internals/managers.py

+1-13
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,6 @@ def diff(self, n: int) -> Self:
378378
# only reached with self.ndim == 2
379379
return self.apply("diff", n=n)
380380

381-
def shift(self, periods: int, fill_value) -> Self:
382-
if fill_value is lib.no_default:
383-
fill_value = None
384-
385-
return self.apply("shift", periods=periods, fill_value=fill_value)
386-
387381
def astype(self, dtype, copy: bool | None = False, errors: str = "raise") -> Self:
388382
if copy is None:
389383
if using_copy_on_write():
@@ -1463,7 +1457,6 @@ def quantile(
14631457
self,
14641458
*,
14651459
qs: Index, # with dtype float 64
1466-
axis: AxisInt = 0,
14671460
interpolation: QuantileInterpolation = "linear",
14681461
) -> Self:
14691462
"""
@@ -1473,9 +1466,6 @@ def quantile(
14731466
14741467
Parameters
14751468
----------
1476-
axis: reduction axis, default 0
1477-
consolidate: bool, default True. Join together blocks having same
1478-
dtype
14791469
interpolation : type of interpolation, default 'linear'
14801470
qs : list of the quantiles to be computed
14811471
@@ -1487,14 +1477,12 @@ def quantile(
14871477
# simplify some of the code here and in the blocks
14881478
assert self.ndim >= 2
14891479
assert is_list_like(qs) # caller is responsible for this
1490-
assert axis == 1 # only ever called this way
14911480

14921481
new_axes = list(self.axes)
14931482
new_axes[1] = Index(qs, dtype=np.float64)
14941483

14951484
blocks = [
1496-
blk.quantile(axis=axis, qs=qs, interpolation=interpolation)
1497-
for blk in self.blocks
1485+
blk.quantile(qs=qs, interpolation=interpolation) for blk in self.blocks
14981486
]
14991487

15001488
return type(self)(blocks, new_axes)

0 commit comments

Comments
 (0)