Skip to content

Commit

Permalink
base/test_unique.py: regression test for bad unicode string (#34851)
Browse files Browse the repository at this point in the history
closes #34550
  • Loading branch information
suvayu committed Jun 18, 2020
1 parent c9144ca commit e6e0889
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pandas/tests/base/test_unique.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,19 @@ def test_nunique_null(null_obj, index_or_series_obj):
num_unique_values = len(obj.unique())
assert obj.nunique() == max(0, num_unique_values - 1)
assert obj.nunique(dropna=False) == max(0, num_unique_values)


@pytest.mark.parametrize(
"idx_or_series_w_bad_unicode", [pd.Index(["\ud83d"] * 2), pd.Series(["\ud83d"] * 2)]
)
def test_unique_bad_unicode(idx_or_series_w_bad_unicode):
# regression test for #34550
obj = idx_or_series_w_bad_unicode
result = obj.unique()

if isinstance(obj, pd.Index):
expected = pd.Index(["\ud83d"], dtype=object)
tm.assert_index_equal(result, expected)
else:
expected = np.array(["\ud83d"], dtype=object)
tm.assert_numpy_array_equal(result, expected)

0 comments on commit e6e0889

Please sign in to comment.