Skip to content

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

Merged
merged 8 commits into from
Sep 6, 2024

Conversation

kirill-bash
Copy link
Contributor

@kirill-bash kirill-bash commented Aug 26, 2024

  • Part of #59237 (Replace xxxx with the Github issue number)
  • Tests added: Please use assert_type() to assert the type of any return value

@kirill-bash
Copy link
Contributor Author

kirill-bash commented Aug 26, 2024

@Dr-Irv This is the follow-up to pandas-dev/pandas#59392.

Copy link
Collaborator

@Dr-Irv Dr-Irv left a 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 ?

@kirill-bash kirill-bash requested a review from Dr-Irv August 28, 2024 22:15
@kirill-bash
Copy link
Contributor Author

@Dr-Irv,

I have added a test for the supported arguments.

Comment on lines 371 to 381
@pytest.mark.parametrize(
"drop_arg",
[
{"AAA"}, # set
["AAA"], # list
("AAA",), # tuple
{"AAA": None}, # dict
"AAA", # str
]
)
def test_types_drop_duplicates(drop_arg) -> None:
Copy link
Collaborator

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()

@kirill-bash kirill-bash requested a review from Dr-Irv August 28, 2024 22:59
@kirill-bash
Copy link
Contributor Author

@Dr-Irv,

Updated based on your feedback.

Thanks!

Comment on lines 382 to 386
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)
Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tip!

@kirill-bash kirill-bash requested a review from Dr-Irv August 29, 2024 23:59
Co-authored-by: Irv Lustig <[email protected]>
@kirill-bash kirill-bash requested a review from Dr-Irv September 4, 2024 00:54
Copy link
Collaborator

@Dr-Irv Dr-Irv left a 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.

@kirill-bash kirill-bash requested a review from Dr-Irv September 6, 2024 20:22
Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @kirill-bash

@Dr-Irv Dr-Irv merged commit 3299527 into pandas-dev:main Sep 6, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants