Skip to content

REF: de-duplicate methods, remove unused kwd #53886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 0 additions & 8 deletions pandas/core/internals/array_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
]
Expand Down
6 changes: 6 additions & 0 deletions pandas/core/internals/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 0 additions & 4 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,6 @@ def quantile(
self,
qs: Index, # with dtype float64
interpolation: QuantileInterpolation = "linear",
axis: AxisInt = 0,
) -> Block:
"""
compute the quantiles of the
Expand All @@ -1522,16 +1521,13 @@ def quantile(
The quantiles to be computed in float64.
interpolation : str, default 'linear'
Type of interpolation.
axis : int, default 0
Axis to compute.

Returns
-------
Block
"""
# 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)
Expand Down
14 changes: 1 addition & 13 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -1463,7 +1457,6 @@ def quantile(
self,
*,
qs: Index, # with dtype float 64
axis: AxisInt = 0,
interpolation: QuantileInterpolation = "linear",
) -> Self:
"""
Expand All @@ -1473,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

Expand All @@ -1487,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)
Expand Down