Skip to content

Commit 45d412f

Browse files
CI: Fix flaky test_value_counts_null (#32449)
1 parent 970499d commit 45d412f

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

pandas/tests/base/test_ops.py

+19-5
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,10 @@ def test_value_counts(self, index_or_series_obj):
311311
if isinstance(obj, pd.MultiIndex):
312312
expected.index = pd.Index(expected.index)
313313

314-
# sort_index to avoid switched order when values share the same count
315-
result = result.sort_index()
316-
expected = expected.sort_index()
314+
# TODO: Order of entries with the same count is inconsistent on CI (gh-32449)
315+
if obj.duplicated().any():
316+
result = result.sort_index()
317+
expected = expected.sort_index()
317318
tm.assert_series_equal(result, expected)
318319

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

347-
tm.assert_series_equal(obj.value_counts(), expected)
348+
result = obj.value_counts()
349+
if obj.duplicated().any():
350+
# TODO:
351+
# Order of entries with the same count is inconsistent on CI (gh-32449)
352+
expected = expected.sort_index()
353+
result = result.sort_index()
354+
tm.assert_series_equal(result, expected)
348355

349356
# can't use expected[null_obj] = 3 as
350357
# IntervalIndex doesn't allow assignment
351358
new_entry = pd.Series({np.nan: 3}, dtype=np.int64)
352359
expected = expected.append(new_entry)
353-
tm.assert_series_equal(obj.value_counts(dropna=False), expected)
360+
361+
result = obj.value_counts(dropna=False)
362+
if obj.duplicated().any():
363+
# TODO:
364+
# Order of entries with the same count is inconsistent on CI (gh-32449)
365+
expected = expected.sort_index()
366+
result = result.sort_index()
367+
tm.assert_series_equal(result, expected)
354368

355369
def test_value_counts_inferred(self, index_or_series):
356370
klass = index_or_series

0 commit comments

Comments
 (0)