Skip to content

Test that nan value counts are included when dropna=False. GH#31944 #36783

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 3 commits into from
Oct 6, 2020

Conversation

icanhazcodeplz
Copy link
Contributor

Added test per @Dr-Irv request.

Copy link
Member

@arw2019 arw2019 left a comment

Choose a reason for hiding this comment

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

thanks @icanhazcodeplz for the PR!

Some comments

@@ -274,3 +274,12 @@ def test_value_counts_datetime64(index_or_series):
td2 = klass(td2, name="dt")
result2 = td2.value_counts()
tm.assert_series_equal(result2, expected_s)


def test_value_counts_nan(index_or_series):
Copy link
Member

Choose a reason for hiding this comment

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

I'd call it test_value_counts_with_nan

def test_value_counts_nan(index_or_series):
"""Test that nan value counts are included when dropna=False. GH#31944"""
klass = index_or_series
s_values = [True, pd.NA, np.nan]
Copy link
Member

Choose a reason for hiding this comment

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

call this data or values

s_values = [True, pd.NA, np.nan]
s = klass(s_values)
expected = Series([2, 1], index=[pd.NA, True])
tm.assert_series_equal(s.value_counts(dropna=False), expected)
Copy link
Member

Choose a reason for hiding this comment

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

you wanna define res = s.value_counts(dropna=False) and then tm.assert_series_equal(res, expected)



def test_value_counts_nan(index_or_series):
"""Test that nan value counts are included when dropna=False. GH#31944"""
Copy link
Member

Choose a reason for hiding this comment

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

# GH31944 is enough here

Copy link
Member

@arw2019 arw2019 left a comment

Choose a reason for hiding this comment

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

lgtm

one nit pick. Also could you parametrize on dropna (True/False) - I assume we don't test it or we should have been testing dropna=False too

klass = index_or_series
values = [True, pd.NA, np.nan]
s = klass(values)
expected = Series([2, 1], index=[pd.NA, True])
Copy link
Member

Choose a reason for hiding this comment

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

nit-pick: can you move this to after res
That way this reads: construct result, construct expected result, compare result with expected

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, makes sense!

@jreback jreback added Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Testing pandas testing functions or related to the test suite labels Oct 2, 2020
@icanhazcodeplz
Copy link
Contributor Author

Hi y'all, any other changes for this pull request?

@jreback jreback added this to the 1.2 milestone Oct 6, 2020
@jreback jreback merged commit ed2dc9b into pandas-dev:master Oct 6, 2020
@jreback
Copy link
Contributor

jreback commented Oct 6, 2020

thanks @icanhazcodeplz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Errors in pandas._libs.lib.maybe_convert_objects leading to use of uninitialized memory
3 participants