Skip to content

fix Rolling for multi-index and reversed index. #28297

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 12 commits into from
Oct 22, 2019
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix rolling on multi-index level
  • Loading branch information
Jan Škoda committed Sep 6, 2019
commit de83db4c6ac413b6b78488a2f3677c82eacbb483
8 changes: 5 additions & 3 deletions pandas/core/window/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def _create_blocks(self):
obj = self._selected_obj

# filter out the on from the object
if self.on is not None:
if self.on is not None and not isinstance(self.on, Index):
if obj.ndim == 2:
obj = obj.reindex(columns=obj.columns.difference([self.on]), copy=False)
blocks = obj._to_dict_of_blocks(copy=False).values()
Expand Down Expand Up @@ -1709,8 +1709,10 @@ def _validate_monotonic(self):
"""
Validate monotonic (increasing or decreasing).
"""
if not self._on.is_monotonic_increasing and self._on.is_monotonic_decreasing:
formatted = self.on or "index"
if not self._on.is_monotonic_increasing and not self._on.is_monotonic_decreasing:
formatted = self.on
if self.on is None:
formatted = "index"
raise ValueError("{0} must be monotonic".format(formatted))

def _validate_freq(self):
Expand Down