-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CLN: enforce deprecation of the method
keyword on df.fillna
#57760
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
CLN: enforce deprecation of the method
keyword on df.fillna
#57760
Conversation
method
in df.fillna
method
keyword on df.fillna
I enforced deprecation of the @jbrockmendel, could you please take a look at this PR? I think CI failures are unrelated to my changes. |
@@ -909,14 +893,14 @@ def test_bfill(self): | |||
[0.0, 1.0, 2.0, 3.0, 4.0], index=date_range("2020-01-01", periods=5) | |||
) | |||
ts.iloc[2] = np.nan | |||
tm.assert_series_equal(ts.bfill(), ts.fillna(method="bfill")) | |||
tm.assert_series_equal(ts.bfill(), ts.bfill()) |
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 assertion looks no-longer-useful
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 on L883
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.
Thank you for reviewing this PR. I removed these useless tests.
@@ -809,7 +797,7 @@ def test_fillna_f32_upcast_with_dict(self): | |||
|
|||
def test_fillna_invalid_method(self, datetime_series): | |||
try: | |||
datetime_series.fillna(method="ffil") | |||
datetime_series.ffill() |
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 missing the point of the test
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.
thanks, I removed the test
tm.assert_frame_equal(result, tsframe.fillna(method="bfill")) | ||
# TODO: what is this even testing? | ||
result = tsframe.bfill() | ||
tm.assert_frame_equal(result, tsframe.bfill()) |
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 not a useful test (per the comment), can just be removed
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.
done
"instead.", | ||
FutureWarning, | ||
stacklevel=find_stack_level(), | ||
if isinstance(value, (list, tuple)): |
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.
Could you check if we have a test where value
is a np.array
or pd.Series
? Given the error message, I would expect this check to be something like if not (is_scalar(value) or isinstance(value, dict))
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.
we have test_fillna_series
in pandas/tests/extension/base/missing.py
where we fill with a series
pandas/pandas/tests/extension/base/missing.py
Lines 123 to 141 in 3132971
def test_fillna_series(self, data_missing): | |
fill_value = data_missing[1] | |
ser = pd.Series(data_missing) | |
result = ser.fillna(fill_value) | |
expected = pd.Series( | |
data_missing._from_sequence( | |
[fill_value, fill_value], dtype=data_missing.dtype | |
) | |
) | |
tm.assert_series_equal(result, expected) | |
# Fill with a series | |
result = ser.fillna(expected) | |
tm.assert_series_equal(result, expected) | |
# Fill with a series not affecting the missing values | |
result = ser.fillna(ser) | |
tm.assert_series_equal(result, ser) |
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.
in pandas/tests/frame/methods/test_fillna.py
I found test_fillna_invalid_value
.
pandas/pandas/tests/frame/methods/test_fillna.py
Lines 563 to 577 in 97c31a6
def test_fillna_invalid_value(self, float_frame): | |
# list | |
msg = '"value" parameter must be a scalar or dict, but you passed a "{}"' | |
with pytest.raises(TypeError, match=msg.format("list")): | |
float_frame.fillna([1, 2]) | |
# tuple | |
with pytest.raises(TypeError, match=msg.format("tuple")): | |
float_frame.fillna((1, 2)) | |
# frame with series | |
msg = ( | |
'"value" parameter must be a scalar, dict or Series, but you ' | |
'passed a "DataFrame"' | |
) | |
with pytest.raises(TypeError, match=msg): | |
float_frame.iloc[:, 0].fillna(float_frame) |
In this test we check if for value: list, tuple or DataFrame
fillna raises TypeError
.
We don't validate values: np.array and Series
in this tests though. I checked, for examples below
df = DataFrame({"a": [1, None, 3]})
df.iloc[:, 0].fillna(value=np.array([1, 0]))
we get the TypeError: TypeError: "value" parameter must be a scalar, dict or Series, but you passed a "ndarray"
Should I add a check for np.array
and maybe correct the condition in if
statement?
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.
Thanks for looking! Since we have a test with np.array
and check that we're raising the error correctly so no need to add the check
Thanks @natmokval |
Thanks @mroeschke for reviewing this PR. |
…as-dev#57760) * enforce deprecation of param method in df.fillna: correct def fillna, fix tests * correct def fillna, fix tests * correct an example in v0.10.0, fix test * add a note to v3.0.0 * remove an entry from ignored_doctest_warnings * fix pylint error in test_sparse.py * correct fillna docstring * correct fillna docstring II * correct tests
xref #53496
enforced deprecation of the
method
keyword ondf.fillna/ser.fillna