-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: fixed fillna('') on a Int64 column causes TypeError: <U3 cannot b… #44870
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
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 |
---|---|---|
|
@@ -647,3 +647,87 @@ def test_fillna_nonconsolidated_frame(): | |
df_nonconsol = df.pivot("i1", "i2") | ||
result = df_nonconsol.fillna(0) | ||
assert result.isna().sum().sum() == 0 | ||
|
||
|
||
def test_fillna_with_int_and_string_nonempty(): | ||
df = DataFrame( | ||
{ | ||
"A": [1, 2, np.nan], | ||
"B": [4, np.nan, 8], | ||
}, | ||
dtype="Int64", | ||
) | ||
df.fillna("nan") | ||
|
||
expected = df = DataFrame( | ||
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. probably don't want to set both 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. same in each case below 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. Interesting, I don't remember setting both df and expected like that - might have been a product of running pre-commit or something else? I can try to change this asap. 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't imagine the pre-commit tooling doing this. most likely just a typo. happens to us all. |
||
{ | ||
"A": [1, 2, " "], | ||
"B": [4, " ", 8], | ||
}, | ||
dtype="Int64", | ||
) | ||
|
||
tm.assert_frame_equal(df, expected) | ||
|
||
|
||
def test_fillna_with_int_and_string_empty(): | ||
df = DataFrame( | ||
{ | ||
"A": [1, 2, np.nan], | ||
"B": [4, np.nan, 8], | ||
}, | ||
dtype="Int64", | ||
) | ||
df.fillna(" ") | ||
|
||
expected = df = DataFrame( | ||
{ | ||
"A": [1, 2, " "], | ||
"B": [4, " ", 8], | ||
}, | ||
dtype="Int64", | ||
) | ||
|
||
tm.assert_frame_equal(df, expected) | ||
|
||
|
||
def test_fillna_with_float_and_string_nonempty(): | ||
df = DataFrame( | ||
{ | ||
"A": [1, 2, np.nan], | ||
"B": [4, np.nan, 8], | ||
}, | ||
dtype="Float64", | ||
) | ||
df.fillna("nan") | ||
|
||
expected = df = DataFrame( | ||
{ | ||
"A": [1, 2, " "], | ||
"B": [4, " ", 8], | ||
}, | ||
dtype="Float64", | ||
) | ||
|
||
tm.assert_frame_equal(df, expected) | ||
|
||
|
||
def test_fillna_with_float_and_string_empty(): | ||
df = DataFrame( | ||
{ | ||
"A": [1, 2, np.nan], | ||
"B": [4, np.nan, 8], | ||
}, | ||
dtype="Float64", | ||
) | ||
df.fillna(" ") | ||
|
||
expected = df = DataFrame( | ||
{ | ||
"A": [1, 2, " "], | ||
"B": [4, " ", 8], | ||
}, | ||
dtype="Float64", | ||
) | ||
|
||
tm.assert_frame_equal(df, expected) |
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 is going to change behavior in an unwanted way. The issue is with 'fillna' with an Int64 dtype, not the existence of Int64 dtypes
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.
Agreed - as mentioned above in the description this contribution is for a final class project. Just trying to get a feel for contributing to open source software.
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.
Are you planning to follow-up on this? That's an important part of the contribution process!