Skip to content

[ArrayManager] Remove apply_with_block usage for diff() #40079

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
Feb 27, 2021
Merged
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
8 changes: 7 additions & 1 deletion pandas/core/internals/array_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,13 @@ def putmask(self, mask, new, align: bool = True):
)

def diff(self, n: int, axis: int) -> ArrayManager:
return self.apply_with_block("diff", n=n, axis=axis)
axis = self._normalize_axis(axis)
if axis == 1:
# DataFrame only calls this for n=0, in which case performing it
# with axis=0 is equivalent
assert n == 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment on why this is expected (presumably the caller checks?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, DataFrame diff already special cases that (and basically "misuses" Manager.diff with a wrong axis for n=0, in which case the axis doesn't matter).
Will add a comment for that.

axis = 0
return self.apply(algos.diff, n=n, axis=axis)

def interpolate(self, **kwargs) -> ArrayManager:
return self.apply_with_block("interpolate", **kwargs)
Expand Down