Skip to content

Commit 8c69608

Browse files
committed
Better error message regex
1 parent aa2398f commit 8c69608

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

pandas/tests/test_algos.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111

1212
from pandas._libs import (
1313
algos as libalgos, groupby as libgroupby, hashtable as ht)
14-
from pandas.compat import PY2, lrange, range
15-
from pandas.compat.numpy import np_array_datetime64_compat
14+
from pandas.compat import lrange, range
15+
from pandas.compat.numpy import (
16+
_np_version_under1p14, np_array_datetime64_compat)
1617
import pandas.util._test_decorators as td
1718

1819
from pandas.core.dtypes.dtypes import CategoricalDtype as CDT
@@ -224,14 +225,15 @@ def test_factorize_tuple_list(self, data, expected_label, expected_level):
224225
dtype=object)
225226
tm.assert_numpy_array_equal(result[1], expected_level_array)
226227

227-
@pytest.mark.skipif(PY2, reason="pytest.raises match regex fails")
228228
def test_complex_sorting(self):
229229
# gh 12666 - check no segfault
230230
x17 = np.array([complex(i) for i in range(17)], dtype=object)
231231

232-
msg = (r"'(<|>)' not supported between instances of 'complex' and"
233-
r" 'complex'|"
234-
r"unorderable types: complex\(\) (<|>) complex\(\)")
232+
msg = (r"unorderable types: {0} [<>] {0}".format(r"complex\(\)")
233+
if _np_version_under1p14 else
234+
r"'[<>]' not supported between instances of {0} and {0}".format(
235+
"'complex'")
236+
)
235237
with pytest.raises(TypeError, match=msg):
236238
algos.factorize(x17[::-1], sort=True)
237239

pandas/tests/test_sorting.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from numpy import nan
88
import pytest
99

10-
from pandas.compat import PY2
10+
from pandas.compat.numpy import _np_version_under1p14
1111

1212
from pandas import DataFrame, MultiIndex, Series, compat, concat, merge
1313
from pandas.core import common as com
@@ -405,15 +405,16 @@ def test_mixed_integer_from_list(self):
405405
expected = np.array([0, 0, 1, 'a', 'b', 'b'], dtype=object)
406406
tm.assert_numpy_array_equal(result, expected)
407407

408-
@pytest.mark.skipif(PY2, reason="pytest.raises match regex fails")
409408
def test_unsortable(self):
410409
# GH 13714
411410
arr = np.array([1, 2, datetime.now(), 0, 3], dtype=object)
412-
msg = (r"'(<|>)' not supported between instances of ('"
413-
r"datetime\.datetime' and 'int'|'int' and 'datetime\.datetime"
414-
r"')|"
415-
r"unorderable types: int\(\) < datetime\.datetime\(\)|"
416-
r"unorderable types: datetime\.datetime\(\) < int\(\)")
411+
msg = (r"unorderable types: ({0} [<>] {1}|{1} [<>] {0})".format(
412+
r"int\(\)", r"datetime\.datetime\(\)") # noqa: E126
413+
if _np_version_under1p14 else
414+
(r"'[<>]' not supported between instances of "
415+
r"({0} and {1}|{1} and {0})").format(
416+
"'int'", r"'datetime\.datetime'")
417+
)
417418
if compat.PY2:
418419
# RuntimeWarning: tp_compare didn't return -1 or -2 for exception
419420
with warnings.catch_warnings():

0 commit comments

Comments
 (0)