Skip to content

Commit 1a5ac31

Browse files
fangchenliyeshsurya
authored andcommitted
COMPAT: more error msg compat for py310 (pandas-dev#41253)
1 parent 1573e17 commit 1a5ac31

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed

pandas/tests/indexes/ranges/test_constructors.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ def test_constructor_range(self):
119119
expected = RangeIndex(1, 5, 2)
120120
tm.assert_index_equal(result, expected, exact=True)
121121

122-
msg = r"^from_range\(\) got an unexpected keyword argument"
122+
msg = (
123+
r"(RangeIndex.)?from_range\(\) got an unexpected keyword argument( 'copy')?"
124+
)
123125
with pytest.raises(TypeError, match=msg):
124126
RangeIndex.from_range(range(10), copy=True)
125127

pandas/tests/indexes/test_numeric.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ def test_constructor_invalid(self):
242242
with pytest.raises((TypeError, ValueError), match=msg):
243243
index_cls(["a", "b", 0.0])
244244

245-
msg = r"float\(\) argument must be a string or a number, not 'Timestamp'"
245+
msg = (
246+
r"float\(\) argument must be a string or a( real)? number, not 'Timestamp'"
247+
)
246248
with pytest.raises(TypeError, match=msg):
247249
index_cls([Timestamp("20130101")])
248250

pandas/tests/io/json/test_ujson.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -828,65 +828,65 @@ def test_0d_array(self):
828828
(
829829
[{}, []],
830830
ValueError,
831-
"nesting not supported for object or variable length dtypes",
831+
r"nesting not supported for object or variable length dtypes",
832832
{},
833833
),
834834
(
835835
[42, None],
836836
TypeError,
837-
"int() argument must be a string, a bytes-like object or a number, "
838-
"not 'NoneType'",
837+
r"int\(\) argument must be a string, a bytes-like object or a( real)? "
838+
r"number, not 'NoneType'",
839839
{},
840840
),
841841
(
842842
[["a"], 42],
843843
ValueError,
844-
"Cannot decode multidimensional arrays with variable length elements "
845-
"to numpy",
844+
r"Cannot decode multidimensional arrays with variable length elements "
845+
r"to numpy",
846846
{},
847847
),
848848
(
849849
[42, {}, "a"],
850850
TypeError,
851-
"int() argument must be a string, a bytes-like object or a number, "
852-
"not 'dict'",
851+
r"int\(\) argument must be a string, a bytes-like object or a( real)? "
852+
r"number, not 'dict'",
853853
{},
854854
),
855855
(
856856
[42, ["a"], 42],
857857
ValueError,
858-
"invalid literal for int() with base 10: 'a'",
858+
r"invalid literal for int\(\) with base 10: 'a'",
859859
{},
860860
),
861861
(
862862
["a", "b", [], "c"],
863863
ValueError,
864-
"nesting not supported for object or variable length dtypes",
864+
r"nesting not supported for object or variable length dtypes",
865865
{},
866866
),
867867
(
868868
[{"a": "b"}],
869869
ValueError,
870-
"Cannot decode multidimensional arrays with variable length elements "
871-
"to numpy",
870+
r"Cannot decode multidimensional arrays with variable length elements "
871+
r"to numpy",
872872
{"labelled": True},
873873
),
874874
(
875875
{"a": {"b": {"c": 42}}},
876876
ValueError,
877-
"labels only supported up to 2 dimensions",
877+
r"labels only supported up to 2 dimensions",
878878
{"labelled": True},
879879
),
880880
(
881881
[{"a": 42, "b": 23}, {"c": 17}],
882882
ValueError,
883-
"cannot reshape array of size 3 into shape (2,1)",
883+
r"cannot reshape array of size 3 into shape \(2,1\)",
884884
{"labelled": True},
885885
),
886886
],
887887
)
888888
def test_array_numpy_except(self, bad_input, exc_type, err_msg, kwargs):
889-
with pytest.raises(exc_type, match=re.escape(err_msg)):
889+
with pytest.raises(exc_type, match=err_msg):
890890
ujson.decode(ujson.dumps(bad_input), numpy=True, **kwargs)
891891

892892
def test_array_numpy_labelled(self):

pandas/tests/scalar/timestamp/test_constructors.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import pytest
1111
import pytz
1212

13+
from pandas.compat import PY310
1314
from pandas.errors import OutOfBoundsDatetime
1415

1516
from pandas import (
@@ -223,7 +224,11 @@ def test_constructor_tz_or_tzinfo(self):
223224

224225
def test_constructor_positional(self):
225226
# see gh-10758
226-
msg = "an integer is required"
227+
msg = (
228+
"'NoneType' object cannot be interpreted as an integer"
229+
if PY310
230+
else "an integer is required"
231+
)
227232
with pytest.raises(TypeError, match=msg):
228233
Timestamp(2000, 1)
229234

0 commit comments

Comments
 (0)