Skip to content

ENH: Add dropna argument to DataFrame.value_counts() #41334

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

Conversation

connesy
Copy link
Contributor

@connesy connesy commented May 5, 2021

Copy link
Member

@phofl phofl left a comment

Choose a reason for hiding this comment

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

looks good, small comments

@lithomas1 lithomas1 added Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff API - Consistency Internal Consistency of API/Behavior labels May 6, 2021
@@ -100,3 +100,47 @@ def test_data_frame_value_counts_empty_normalize():
expected = pd.Series([], dtype=np.float64)

tm.assert_series_equal(result, expected)


def test_data_frame_value_counts_dropna_true(nulls_fixture):
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to parameterize this test with dropna instead of 2 separate tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure how to do that while using the nulls_fixture. Any suggestion is welcome!

Copy link
Member

Choose a reason for hiding this comment

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

You can simply add another parametrization:

@pytest.mark.parametrize("x", [1, 2])
def test_data_frame_value_counts_dropna_true(nulls_fixture, x):
    pass

But I don't know if this wouldn't make it more complicated here.

Copy link
Contributor Author

@connesy connesy May 10, 2021

Choose a reason for hiding this comment

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

The issue is that the input and expected dataframes are quite different in the two tests, so they would need to be defined as part of the parametrization. But both are also defined using the values from the nulls_fixture, so I would somehow need to use the fixture values in the parametrization, and I'm not sure how I can do both.

Copy link
Member

Choose a reason for hiding this comment

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

Ah now I get it. if else is the only way here, but I think this would make it more complicated than is worth

@connesy
Copy link
Contributor Author

connesy commented May 10, 2021

Two of the builds failed due to tests that I have not touched. It seems like those tests fail quite often?
Is it possible to rerun those builds?

@jreback jreback added this to the 1.3 milestone May 10, 2021
@jreback jreback merged commit 670e9be into pandas-dev:master May 10, 2021
@jreback
Copy link
Contributor

jreback commented May 10, 2021

thanks @connesy very nice

That CI build fails occasionaly and is unrelated here, so all good.

JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
@connesy connesy deleted the issue41325/add-dropna-dataframe-value-counts branch September 8, 2022 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff API - Consistency Internal Consistency of API/Behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: Add dropna argument to pd.DataFrame.value_counts()
5 participants