-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Fix for fillna ignoring axis=1 parameter (issues #17399 #17409) #28441
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
Changes from 2 commits
d9f44ed
0ed4f15
6837029
38c40d9
7536477
df26386
313e934
e1863fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -671,6 +671,14 @@ def test_fillna_columns(self): | |
expected = df.astype(float).fillna(method="ffill", axis=1) | ||
assert_frame_equal(result, expected) | ||
|
||
def test_fillna_columns(self): | ||
df = DataFrame(np.random.randn(10, 4)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add GH 17399 as a comment here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also generally for test you can simplify by just constructing a DataFrame with literal values instead of random data - should make smaller and help readability There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added the comment (and properly fixed the test function name). I'm afraid I found this bug on the first day of my learning to use pandas, so I'm not quite there yet to write a custom test. Rather, I used/modified the existing one from test_fillna_columns() There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm this test works on master for me without these changes - is this capturing the changed behavior? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jorvis can you respond here? Need to make sure we're actually fixing a real issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll try to make a more direct test case. This is the demo that made me find it: After that I found an existing PR which had grown stale, and @jreback asked me to update it, so I thought I'd give it a try. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have updated it now to reflect a test similar to that Jupyter image above. |
||
df.iloc[1:4, 1:4] = nan | ||
expected = df.copy() | ||
expected.iloc[1:4, 1:4] = 0 | ||
result = df.fillna(value=0, axis=1) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
def test_fillna_invalid_method(self, float_frame): | ||
with pytest.raises(ValueError, match="ffil"): | ||
float_frame.fillna(method="ffil") | ||
|
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.
As is, this is a breaking API change. To be safe, you would need to put
axis
at the end.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 also add an annotation for
axis
? Should be importable frompandas._typing
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.
I have just done this, thanks.
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.
Sorry, I'm not sure what that means. Could you direct me to an example or docs?
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.
Yea so a variable annotation. You'd essentially do:
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.
OK, thanks. I have pushed this.