Skip to content

COMPAT: more error msg compat for py310 #41253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pandas/tests/indexes/ranges/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/indexes/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")])

Expand Down
28 changes: 14 additions & 14 deletions pandas/tests/io/json/test_ujson.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 6 additions & 1 deletion pandas/tests/scalar/timestamp/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pytest
import pytz

from pandas.compat import PY310
from pandas.errors import OutOfBoundsDatetime

from pandas import (
Expand Down Expand Up @@ -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)

Expand Down