Skip to content

Commit bfc310f

Browse files
committed
Add inverse to test_categorical
1 parent 39a2e64 commit bfc310f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pandas/tests/test_algos.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,20 @@ def test_categorical(self, method, box, ordered):
458458

459459
assert_series_or_index_or_array_or_categorical_equal(result, expected)
460460

461+
if method == pd.unique:
462+
# [Series/Index].unique do not yet support return_inverse=True
463+
464+
# reuse result as expected outcome of return_inverse case
465+
expected_uniques = result.copy()
466+
result_uniques, result_inverse = method(c, return_inverse=True)
467+
468+
assert_series_or_index_or_array_or_categorical_equal(
469+
result_uniques, expected_uniques)
470+
471+
# reconstruction can only work if inverse is correct
472+
reconstr = box(result_uniques[result_inverse])
473+
assert_series_or_index_or_array_or_categorical_equal(reconstr, c)
474+
461475
def test_datetime64tz_aware(self):
462476
# GH 15939
463477

0 commit comments

Comments
 (0)