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 3 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
22 changes: 17 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()
if obj.dtype == np.float16:
# TODO: Order of entries with the same count is inconsistent on CI
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,24 @@ 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.dtype == np.float16:
# TODO: Order of entries with the same count is inconsistent on CI
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.dtype == np.float16:
# TODO: Order of entries with the same count is inconsistent on CI
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