From d73a8ea9a1646930726cf8d527e67ffedcfd6053 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Sat, 1 May 2021 16:17:38 -0500 Subject: [PATCH 1/3] COMPAT: datetime compat for py310 --- pandas/tests/scalar/timestamp/test_constructors.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pandas/tests/scalar/timestamp/test_constructors.py b/pandas/tests/scalar/timestamp/test_constructors.py index 98ec4de614a07..2340d154e9e10 100644 --- a/pandas/tests/scalar/timestamp/test_constructors.py +++ b/pandas/tests/scalar/timestamp/test_constructors.py @@ -10,6 +10,7 @@ import pytest import pytz +from pandas.compat import PY310 from pandas.errors import OutOfBoundsDatetime from pandas import ( @@ -223,7 +224,11 @@ def test_constructor_tz_or_tzinfo(self): def test_constructor_positional(self): # see gh-10758 - msg = "an integer is required" + msg = ( + "'NoneType' object cannot be interpreted as an integer" + if PY310 + else "an integer is required" + ) with pytest.raises(TypeError, match=msg): Timestamp(2000, 1) From 20c59d601c5a9f271196ae832596679ee98b5671 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Sat, 1 May 2021 17:37:44 -0500 Subject: [PATCH 2/3] fix more error msg compat --- pandas/tests/indexes/test_numeric.py | 4 +++- pandas/tests/io/json/test_ujson.py | 28 ++++++++++++++-------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/pandas/tests/indexes/test_numeric.py b/pandas/tests/indexes/test_numeric.py index 5f02f9625a9e6..c5dc84dac0fd2 100644 --- a/pandas/tests/indexes/test_numeric.py +++ b/pandas/tests/indexes/test_numeric.py @@ -242,7 +242,9 @@ def test_constructor_invalid(self): with pytest.raises((TypeError, ValueError), match=msg): index_cls(["a", "b", 0.0]) - msg = r"float\(\) argument must be a string or a number, not 'Timestamp'" + msg = ( + r"float\(\) argument must be a string or a( real)? number, not 'Timestamp'" + ) with pytest.raises(TypeError, match=msg): index_cls([Timestamp("20130101")]) diff --git a/pandas/tests/io/json/test_ujson.py b/pandas/tests/io/json/test_ujson.py index a44d47470eb5e..805f6b8dbe461 100644 --- a/pandas/tests/io/json/test_ujson.py +++ b/pandas/tests/io/json/test_ujson.py @@ -828,65 +828,65 @@ def test_0d_array(self): ( [{}, []], ValueError, - "nesting not supported for object or variable length dtypes", + r"nesting not supported for object or variable length dtypes", {}, ), ( [42, None], TypeError, - "int() argument must be a string, a bytes-like object or a number, " - "not 'NoneType'", + r"int\(\) argument must be a string, a bytes-like object or a( real)? " + r"number, not 'NoneType'", {}, ), ( [["a"], 42], ValueError, - "Cannot decode multidimensional arrays with variable length elements " - "to numpy", + r"Cannot decode multidimensional arrays with variable length elements " + r"to numpy", {}, ), ( [42, {}, "a"], TypeError, - "int() argument must be a string, a bytes-like object or a number, " - "not 'dict'", + r"int\(\) argument must be a string, a bytes-like object or a( real)? " + r"number, not 'dict'", {}, ), ( [42, ["a"], 42], ValueError, - "invalid literal for int() with base 10: 'a'", + r"invalid literal for int\(\) with base 10: 'a'", {}, ), ( ["a", "b", [], "c"], ValueError, - "nesting not supported for object or variable length dtypes", + r"nesting not supported for object or variable length dtypes", {}, ), ( [{"a": "b"}], ValueError, - "Cannot decode multidimensional arrays with variable length elements " - "to numpy", + r"Cannot decode multidimensional arrays with variable length elements " + r"to numpy", {"labelled": True}, ), ( {"a": {"b": {"c": 42}}}, ValueError, - "labels only supported up to 2 dimensions", + r"labels only supported up to 2 dimensions", {"labelled": True}, ), ( [{"a": 42, "b": 23}, {"c": 17}], ValueError, - "cannot reshape array of size 3 into shape (2,1)", + r"cannot reshape array of size 3 into shape \(2,1\)", {"labelled": True}, ), ], ) def test_array_numpy_except(self, bad_input, exc_type, err_msg, kwargs): - with pytest.raises(exc_type, match=re.escape(err_msg)): + with pytest.raises(exc_type, match=err_msg): ujson.decode(ujson.dumps(bad_input), numpy=True, **kwargs) def test_array_numpy_labelled(self): From 011d077d09ea628089c99417eeb54b86add2ddbf Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Sat, 1 May 2021 18:58:16 -0500 Subject: [PATCH 3/3] more error msg compat --- pandas/tests/indexes/ranges/test_constructors.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/tests/indexes/ranges/test_constructors.py b/pandas/tests/indexes/ranges/test_constructors.py index 9539b0ff7cdba..e306b6e67cf7f 100644 --- a/pandas/tests/indexes/ranges/test_constructors.py +++ b/pandas/tests/indexes/ranges/test_constructors.py @@ -119,7 +119,9 @@ def test_constructor_range(self): expected = RangeIndex(1, 5, 2) tm.assert_index_equal(result, expected, exact=True) - msg = r"^from_range\(\) got an unexpected keyword argument" + msg = ( + r"(RangeIndex.)?from_range\(\) got an unexpected keyword argument( 'copy')?" + ) with pytest.raises(TypeError, match=msg): RangeIndex.from_range(range(10), copy=True)