Skip to content

CI: Fix flaky test_value_counts_null #32449

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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions pandas/tests/base/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,10 @@ def test_value_counts(self, index_or_series_obj):
if isinstance(obj, pd.MultiIndex):
expected.index = pd.Index(expected.index)

# sort_index to avoid switched order when values share the same count
result = result.sort_index()
expected = expected.sort_index()
# TODO: Order of entries with the same count is inconsistent on CI (gh-32449)
Copy link
Member

Choose a reason for hiding this comment

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

Is there an open issue for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

xref: #32514

if obj.duplicated().any():
result = result.sort_index()
expected = expected.sort_index()
tm.assert_series_equal(result, expected)

@pytest.mark.parametrize("null_obj", [np.nan, None])
Expand Down Expand Up @@ -344,13 +345,26 @@ def test_value_counts_null(self, null_obj, index_or_series_obj):
expected = pd.Series(dict(counter.most_common()), dtype=np.int64)
expected.index = expected.index.astype(obj.dtype)

tm.assert_series_equal(obj.value_counts(), expected)
result = obj.value_counts()
if obj.duplicated().any():
# TODO:
# Order of entries with the same count is inconsistent on CI (gh-32449)
expected = expected.sort_index()
result = result.sort_index()
tm.assert_series_equal(result, expected)

# can't use expected[null_obj] = 3 as
# IntervalIndex doesn't allow assignment
new_entry = pd.Series({np.nan: 3}, dtype=np.int64)
expected = expected.append(new_entry)
tm.assert_series_equal(obj.value_counts(dropna=False), expected)

result = obj.value_counts(dropna=False)
if obj.duplicated().any():
# TODO:
# Order of entries with the same count is inconsistent on CI (gh-32449)
expected = expected.sort_index()
result = result.sort_index()
tm.assert_series_equal(result, expected)

def test_value_counts_inferred(self, index_or_series):
klass = index_or_series
Expand Down