Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add inverse to test_timedelta64_dtype_array_returned
  • Loading branch information
h-vetinari committed Feb 1, 2019
commit de22c62cbe7acff1851441b25d7dd77992fd05cd
24 changes: 24 additions & 0 deletions pandas/tests/test_algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@
from pandas.util.testing import assert_almost_equal


def assert_series_or_index_or_array_or_categorical_equal(left, right):
if isinstance(left, Series):
tm.assert_series_equal(left, right)
elif isinstance(left, Index):
tm.assert_index_equal(left, right)
elif isinstance(left, np.ndarray):
tm.assert_numpy_array_equal(left, right)
elif isinstance(left, Categorical):
tm.assert_categorical_equal(left, right)
else:
# will fail
assert isinstance(left, (Series, Index, np.ndarray, Categorical))


class TestMatch(object):

def test_ints(self):
Expand Down Expand Up @@ -395,6 +409,16 @@ def test_timedelta64_dtype_array_returned(self, box):
result = algos.unique(obj)
tm.assert_numpy_array_equal(result, expected)

# reuse result as expected outcome of return_inverse case
expected_uniques = result.copy()

result_uniques, result_inverse = algos.unique(obj, return_inverse=True)
tm.assert_numpy_array_equal(result_uniques, expected_uniques)

# reconstruction can only work if inverse is correct
reconstr = box(result_uniques[result_inverse])
assert_series_or_index_or_array_or_categorical_equal(reconstr, obj)

def test_uint64_overflow(self):
s = Series([1, 2, 2**63, 2**63], dtype=np.uint64)
exp = np.array([1, 2, 2**63], dtype=np.uint64)
Expand Down