-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
EA: fillna should accept same type #32414 #43230
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 5 commits
c46b201
02db9f0
b872815
49b693c
edf6af7
12ab6aa
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,27 @@ def test_fillna_categorical_with_new_categories(self, fill_value, expected_outpu | |
result = ser.fillna(fill_value) | ||
tm.assert_series_equal(result, exp) | ||
|
||
@pytest.mark.parametrize( | ||
"fill_value, expected_output", | ||
[ | ||
("B", ["A", "B", "B", "B", "C"]), | ||
("C", ["A", "B", "C", "C", "C"]) | ||
], | ||
) | ||
|
||
def test_series_fill(fill_value, expected_output): | ||
# GH32414 | ||
data = ["A", "B", np.nan, np.nan, "C"] | ||
cat = Categorical(data, categories=["A", "B", "C"]) | ||
ser = Series(cat) | ||
exp = Categorical(expected_output, categories=["A", "B", "C"]) | ||
exp_ser = Series(exp) | ||
result = ser.fillna(fill_value) | ||
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. This does not cover the issue. We need to check with a categorical fill_value too. 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 defined the the fill_value in the pytest parameterized section. There I have provided a fill_value . Do we need to explicitly define that categroical value 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. Could you please ellaborate on this a little more ?? I find it difficult to understand 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. You are not testing everything mentioned in the issue. @mroeschke provided a code snippet there which should be covered 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. In [22]: cat = pd.Categorical(["A", "B", None, "A"]) In [23]: >>> filled = cat.fillna(ser) In [24]: >>> cat.fillna(filled) 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. hey @phofl, this was the code snippet as being provided by @mroeschke, I have tried to add the same thing. Soo i'm asking should I add "B" instead of that fill_value?? 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. okay @phofl , I have checked with categorical_fillna too. I will add the updated code tomorrow positively. I think with that issue will be resolved. Thanks |
||
filled = cat.fillna(fill_value) | ||
tm.assert_almost_equal(result, exp_ser) | ||
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 use and 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. and rename things a bit, this is very hard to read 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. yaa i surely rename it. Thanks for checking that out. |
||
tm.assert_almost_equal(filled, exp) | ||
|
||
|
||
def test_fillna_categorical_raises(self): | ||
data = ["a", np.nan, "b", np.nan, np.nan] | ||
ser = Series(Categorical(data, categories=["a", "b"])) | ||
|
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 rename to tests_fillna_categorical
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.
yaa i will rename it.