-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
REG: DataFrame.shift with axis=1 and CategoricalIndex columns #38504
Conversation
Thanks for taking this. This PR should IMO be part of 1.2, since it’s a regression since 1.1. |
if periods > 0: | ||
result = self.iloc[:, :-periods] | ||
for col in range(min(ncols, abs(periods))): | ||
# TODO(EA2D): doing this in a loop unnecessary with 2D EAs | ||
# Define filler inside loop so we get a copy | ||
filler = self.iloc[:, 0].shift(len(self)) | ||
result.insert(0, col, filler, allow_duplicates=True) | ||
result.insert(0, label, filler, allow_duplicates=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work correctly for periods > 1? Looks like it inserts the same label in all locations, where Id think it should insert self.columns[col]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be benign because we set result.columns directly below. ill add a test to be on the safe side
else: | ||
result = self.iloc[:, -periods:] | ||
for col in range(min(ncols, abs(periods))): | ||
# Define filler inside loop so we get a copy | ||
filler = self.iloc[:, -1].shift(len(self)) | ||
result.insert( | ||
len(result.columns), col, filler, allow_duplicates=True | ||
len(result.columns), label, filler, allow_duplicates=True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above.
# GH#38434 | ||
ci = CategoricalIndex(["a", "b"]) | ||
df = DataFrame([[1, 2], [3, 4]], index=ci, columns=ci) | ||
result = df.shift(axis=1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you test a 3-column dataframe with periods=2
also?
and whatsnew probably not necessary |
added test case with periods=2, removed whatsnew |
@meeseeksdev backport 1.2.x |
This comment has been minimized.
This comment has been minimized.
…tegoricalIndex columns
…ndex columns (#38555) Co-authored-by: jbrockmendel <jbrockmendel@gmail.com>
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff