-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
Deprecate non-keyword arguments in mask #41580
Deprecate non-keyword arguments in mask #41580
Conversation
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 @ShreyDixit
This is off to a good start! Just a few comments, and some pre-commit checks to fixup
pandas/core/generic.py
Outdated
@@ -9236,6 +9237,7 @@ def where( | |||
name="mask", | |||
name_other="where", | |||
) | |||
@deprecate_nonkeyword_arguments(version="2.0", allowed_args=["self", "cond"]) |
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.
let's make this version=None
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.
also, let's allow other
to be positional as well, just like in where
https://github.com/pandas-dev/pandas/pull/41523/files
with tm.assert_produces_warning(FutureWarning, match=msg): | ||
tm.assert_frame_equal(df.mask(cond, other), df.mask(cond, other=other)) |
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 write this as
with tm.assert_produces_warnnig...
result = ...
expected = ...
tm.assert_frame_equal(result, expected)
and construct expected
explicitly
with tm.assert_produces_warning(FutureWarning, match=msg): | ||
tm.assert_series_equal(s.mask(cond, np.nan), s.mask(cond, other=np.nan)) |
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 comments as for the DataFrame test
msg = ( | ||
r"Starting with Pandas version 2\.0 all arguments of mask except for the " | ||
r"arguments 'self' and 'cond' will be keyword-only" | ||
) |
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.
the message will need updating, there's been some changes in deprecate_nonkeyword_arguments
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.
Have made the changes and removed the message entirely.
56e1757
to
f7be5e0
Compare
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.
Generally looks good, just a few comments - also, please remove path_to_file.xlsx
@@ -90,6 +90,18 @@ def test_mask_dtype_bool_conversion(self): | |||
result = bools.mask(mask) | |||
tm.assert_frame_equal(result, expected) | |||
|
|||
def test_mask_pos_args_deprecation(self): | |||
# https://github.com/pandas-dev/pandas/issues/41485 | |||
df = DataFrame(np.random.randn(5, 5)) |
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 construct it explicitly instead of passing in randomly generated numbers? a small dataframe with a single column should be fine
with tm.assert_produces_warning(FutureWarning): | ||
result = df.mask(cond, other, False) | ||
|
||
expected = df.mask(cond, other=other, inplace=False) |
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 construct expected
explicitly (otherwise both result
and expected
go through .mask
)
cond = df > 0 | ||
other = DataFrame(np.random.randn(5, 3)) | ||
|
||
with tm.assert_produces_warning(FutureWarning): |
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 check the warning message? see msg = ...
from the example PR
|
||
expected = Series( | ||
[NA, "this", "that", NA], | ||
index=["id1", "id2", "id3", "id4"], | ||
dtype=StringDtype(), | ||
) | ||
tm.assert_series_equal(result, expected) | ||
|
||
|
||
def test_mask_pos_args_deprecation(): |
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 comments as for the DataFrame test
hmm other is prob ok as a positional as well here |
OK, thanks for stepping in - I'll ask for it to be positional in the |
cond = df % 2 == 0 | ||
|
||
msg = ( | ||
r"In a future version of pandas all arguments of NDFrame.mask except for " |
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.
should be DataFrame.mask
cond = s % 2 == 0 | ||
|
||
msg = ( | ||
r"In a future version of pandas all arguments of NDFrame.mask except for " |
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.
Series.mask
doc/source/whatsnew/v1.3.0.rst
Outdated
@@ -678,6 +678,7 @@ Deprecations | |||
- Deprecated setting :attr:`Categorical._codes`, create a new :class:`Categorical` with the desired codes instead (:issue:`40606`) | |||
- Deprecated behavior of :meth:`DatetimeIndex.union` with mixed timezones; in a future version both will be cast to UTC instead of object dtype (:issue:`39328`) | |||
- Deprecated using ``usecols`` with out of bounds indices for ``read_csv`` with ``engine="c"`` (:issue:`25623`) | |||
- Deprecated passing arguments (apart from ``cond`` and ``other``) as positional in :meth:`DataFrame.mask` (:issue:`41485`) |
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.
mention Series.mask
as well
01881bb
to
31c98c1
Compare
@ShreyDixit can u rebase |
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 @ShreyDixit lgtm pending green
thanks @ShreyDixit |
Thank you everyone for you guidance |
inplace
#41485