Skip to content

Commit e3183fb

Browse files
committed
TST: Refactor test for complex categorical, xfailing
Only want to xfail just the complex case, so converted to a parametrize.
1 parent e2473f8 commit e3183fb

File tree

1 file changed

+37
-35
lines changed

1 file changed

+37
-35
lines changed

pandas/tests/test_algos.py

+37-35
Original file line numberDiff line numberDiff line change
@@ -819,55 +819,57 @@ def test_duplicated_with_nas(self):
819819
expected = np.array(trues + trues)
820820
tm.assert_numpy_array_equal(result, expected)
821821

822-
def test_numeric_object_likes(self):
823-
cases = [np.array([1, 2, 1, 5, 3,
824-
2, 4, 1, 5, 6]),
825-
np.array([1.1, 2.2, 1.1, np.nan, 3.3,
826-
2.2, 4.4, 1.1, np.nan, 6.6]),
827-
np.array([1 + 1j, 2 + 2j, 1 + 1j, 5 + 5j, 3 + 3j,
828-
2 + 2j, 4 + 4j, 1 + 1j, 5 + 5j, 6 + 6j]),
829-
np.array(['a', 'b', 'a', 'e', 'c',
830-
'b', 'd', 'a', 'e', 'f'], dtype=object),
831-
np.array([1, 2**63, 1, 3**5, 10,
832-
2**63, 39, 1, 3**5, 7], dtype=np.uint64)]
833-
822+
@pytest.mark.parametrize('case', [
823+
np.array([1, 2, 1, 5, 3,
824+
2, 4, 1, 5, 6]),
825+
np.array([1.1, 2.2, 1.1, np.nan, 3.3,
826+
2.2, 4.4, 1.1, np.nan, 6.6]),
827+
pytest.mark.xfail(resaon="Complex bug. GH 16399")(
828+
np.array([1 + 1j, 2 + 2j, 1 + 1j, 5 + 5j, 3 + 3j,
829+
2 + 2j, 4 + 4j, 1 + 1j, 5 + 5j, 6 + 6j])
830+
),
831+
np.array(['a', 'b', 'a', 'e', 'c',
832+
'b', 'd', 'a', 'e', 'f'], dtype=object),
833+
np.array([1, 2**63, 1, 3**5, 10, 2**63, 39, 1, 3**5, 7],
834+
dtype=np.uint64),
835+
])
836+
def test_numeric_object_likes(self, case):
834837
exp_first = np.array([False, False, True, False, False,
835838
True, False, True, True, False])
836839
exp_last = np.array([True, True, True, True, False,
837840
False, False, False, False, False])
838841
exp_false = exp_first | exp_last
839842

840-
for case in cases:
841-
res_first = algos.duplicated(case, keep='first')
842-
tm.assert_numpy_array_equal(res_first, exp_first)
843+
res_first = algos.duplicated(case, keep='first')
844+
tm.assert_numpy_array_equal(res_first, exp_first)
843845

844-
res_last = algos.duplicated(case, keep='last')
845-
tm.assert_numpy_array_equal(res_last, exp_last)
846+
res_last = algos.duplicated(case, keep='last')
847+
tm.assert_numpy_array_equal(res_last, exp_last)
846848

847-
res_false = algos.duplicated(case, keep=False)
848-
tm.assert_numpy_array_equal(res_false, exp_false)
849+
res_false = algos.duplicated(case, keep=False)
850+
tm.assert_numpy_array_equal(res_false, exp_false)
849851

850-
# index
851-
for idx in [pd.Index(case), pd.Index(case, dtype='category')]:
852-
res_first = idx.duplicated(keep='first')
853-
tm.assert_numpy_array_equal(res_first, exp_first)
852+
# index
853+
for idx in [pd.Index(case), pd.Index(case, dtype='category')]:
854+
res_first = idx.duplicated(keep='first')
855+
tm.assert_numpy_array_equal(res_first, exp_first)
854856

855-
res_last = idx.duplicated(keep='last')
856-
tm.assert_numpy_array_equal(res_last, exp_last)
857+
res_last = idx.duplicated(keep='last')
858+
tm.assert_numpy_array_equal(res_last, exp_last)
857859

858-
res_false = idx.duplicated(keep=False)
859-
tm.assert_numpy_array_equal(res_false, exp_false)
860+
res_false = idx.duplicated(keep=False)
861+
tm.assert_numpy_array_equal(res_false, exp_false)
860862

861-
# series
862-
for s in [Series(case), Series(case, dtype='category')]:
863-
res_first = s.duplicated(keep='first')
864-
tm.assert_series_equal(res_first, Series(exp_first))
863+
# series
864+
for s in [Series(case), Series(case, dtype='category')]:
865+
res_first = s.duplicated(keep='first')
866+
tm.assert_series_equal(res_first, Series(exp_first))
865867

866-
res_last = s.duplicated(keep='last')
867-
tm.assert_series_equal(res_last, Series(exp_last))
868+
res_last = s.duplicated(keep='last')
869+
tm.assert_series_equal(res_last, Series(exp_last))
868870

869-
res_false = s.duplicated(keep=False)
870-
tm.assert_series_equal(res_false, Series(exp_false))
871+
res_false = s.duplicated(keep=False)
872+
tm.assert_series_equal(res_false, Series(exp_false))
871873

872874
def test_datetime_likes(self):
873875

0 commit comments

Comments
 (0)