-
-
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 all 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,21 @@ def test_fillna_columns(self): | |
expected = df.astype(float).fillna(method="ffill", axis=1) | ||
assert_frame_equal(result, expected) | ||
|
||
def test_fillna_rows(self): | ||
#GH17399 | ||
df = pd.DataFrame({ | ||
"a": [1,2,3,4], | ||
"b": [5,np.nan,7,8], | ||
"c": [9,10,11,np.nan]}) | ||
|
||
expected = pd.DataFrame({ | ||
"a": [1,2,3,4], | ||
"b": [5,6,7,8], | ||
"c": [9,10,11,6]}) | ||
|
||
result = df.fillna(df.mean(axis=1)) | ||
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 don't see 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. Maybe we should back up and make sure the behavior I'm seeing is expected then an not a bug. In this notebook I first try to replace NaNs with the column average, then the row average. Doing the first works, but the second silently does nothing. Setting axis=1 on fillna when using the mean where axis=1 causes an error: Currently only can fill with dict/Series column by column. It seems like calling fillna on a frame with NaNs which doesn't fill them is an 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. Yea I also think this test might be missing the point. Can you try getting the issue directly from #17399 to work? I think that is relatively clearly laid out |
||
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.
Is this true in general, or was it just under specific conditions?
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'll try to make a more direct test case. This is the demo that made me find it:
https://imgur.com/a/3ZrXqSv
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.