Skip to content

Commit 7b45be9

Browse files
authored
COMPAT: frame round error msg for py310 (#41301)
1 parent a6db652 commit 7b45be9

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

pandas/core/frame.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -9207,9 +9207,12 @@ def _series_round(s, decimals):
92079207
nv.validate_round(args, kwargs)
92089208

92099209
if isinstance(decimals, (dict, Series)):
9210-
if isinstance(decimals, Series):
9211-
if not decimals.index.is_unique:
9212-
raise ValueError("Index of decimals must be unique")
9210+
if isinstance(decimals, Series) and not decimals.index.is_unique:
9211+
raise ValueError("Index of decimals must be unique")
9212+
if is_dict_like(decimals) and not all(
9213+
is_integer(value) for _, value in decimals.items()
9214+
):
9215+
raise TypeError("Values in decimals must be integers")
92139216
new_cols = list(_dict_round(self, decimals))
92149217
elif is_integer(decimals):
92159218
# Dispatch to Series.round

pandas/tests/frame/methods/test_round.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,12 @@ def test_round(self):
6262

6363
# float input to `decimals`
6464
non_int_round_dict = {"col1": 1, "col2": 0.5}
65-
msg = "integer argument expected, got float"
65+
msg = "Values in decimals must be integers"
6666
with pytest.raises(TypeError, match=msg):
6767
df.round(non_int_round_dict)
6868

6969
# String input
7070
non_int_round_dict = {"col1": 1, "col2": "foo"}
71-
msg = r"an integer is required \(got type str\)"
7271
with pytest.raises(TypeError, match=msg):
7372
df.round(non_int_round_dict)
7473

@@ -78,7 +77,6 @@ def test_round(self):
7877

7978
# List input
8079
non_int_round_dict = {"col1": 1, "col2": [1, 2]}
81-
msg = r"an integer is required \(got type list\)"
8280
with pytest.raises(TypeError, match=msg):
8381
df.round(non_int_round_dict)
8482

@@ -106,7 +104,6 @@ def test_round(self):
106104
# nan in Series round
107105
nan_round_Series = Series({"col1": np.nan, "col2": 1})
108106

109-
msg = "integer argument expected, got float"
110107
with pytest.raises(TypeError, match=msg):
111108
df.round(nan_round_Series)
112109

0 commit comments

Comments
 (0)