-
-
Notifications
You must be signed in to change notification settings - Fork 142
ENH: updating subset types in drop_duplicates/duplicated #986
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
Conversation
@Dr-Irv This is the follow-up to pandas-dev/pandas#59392. |
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 add a test for this in tests/test_frame.py
?
I have added a test for the supported arguments. |
tests/test_frame.py
Outdated
@pytest.mark.parametrize( | ||
"drop_arg", | ||
[ | ||
{"AAA"}, # set | ||
["AAA"], # list | ||
("AAA",), # tuple | ||
{"AAA": None}, # dict | ||
"AAA", # str | ||
] | ||
) | ||
def test_types_drop_duplicates(drop_arg) -> 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.
For the purposes of testing type checks, you have to explicitly put in each of these arguments and can't parameterize. So you'd do:
check(assert_type(df.drop_duplicates({"AAA"}), pd.DataFrame), pd.DataFrame)
check(assert_type(df.drop_duplicates(["AAA"]), pd.DataFrame), pd.DataFrame)
# and similar for the other 3
Then you don't need to do assert_frame_equal()
Updated based on your feedback. Thanks! |
tests/test_frame.py
Outdated
check(assert_type(df.drop_duplicates({"AAA"}), pd.DataFrame), pd.DataFrame) | ||
check(assert_type(df.drop_duplicates(["AAA"]), pd.DataFrame), pd.DataFrame) | ||
check(assert_type(df.drop_duplicates(("AAA",)), pd.DataFrame), pd.DataFrame) | ||
check(assert_type(df.drop_duplicates({"AAA": None}), pd.DataFrame), pd.DataFrame) | ||
check(assert_type(df.drop_duplicates("AAA"), pd.DataFrame), pd.DataFrame) |
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.
With pandas 2.2, the set
and dict
arguments don't work. But they will work in a future release of pandas.
So you need to surround the set
and dict
tests with
if PD_LTE_22:
# Put the 2 tests here
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 the tip!
Co-authored-by: Irv Lustig <[email protected]>
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.
You need to run black on your changed files, or follow the instructions at https://github.com/pandas-dev/pandas-stubs/blob/main/docs/setup.md to set up your environment and install the pre-commit checks.
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 @kirill-bash
assert_type()
to assert the type of any return value