Skip to content

Commit b1cf598

Browse files
committed
change wording in the error msg
1 parent da8f19d commit b1cf598

File tree

9 files changed

+20
-18
lines changed

9 files changed

+20
-18
lines changed

pandas/core/arrays/datetimelike.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1662,7 +1662,7 @@ def _groupby_op(
16621662
if dtype.kind == "M":
16631663
# Adding/multiplying datetimes is not valid
16641664
if how in ["any", "all", "sum", "prod", "cumsum", "cumprod", "var", "skew"]:
1665-
raise TypeError(f"datetime64 type does not support {how} operations")
1665+
raise TypeError(f"datetime64 type does not support operation: '{how}'")
16661666

16671667
elif isinstance(dtype, PeriodDtype):
16681668
# Adding/multiplying Periods is not valid

pandas/core/nanops.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ def nanany(
520520

521521
if values.dtype.kind == "M":
522522
# GH#34479
523-
raise TypeError("datetime64 type does not support any operations")
523+
raise TypeError("datetime64 type does not support operation: 'any'")
524524

525525
values, _ = _get_values(values, skipna, fill_value=False, mask=mask)
526526

@@ -576,7 +576,7 @@ def nanall(
576576

577577
if values.dtype.kind == "M":
578578
# GH#34479
579-
raise TypeError("datetime64 type does not support all operations")
579+
raise TypeError("datetime64 type does not support operation: 'all'")
580580

581581
values, _ = _get_values(values, skipna, fill_value=True, mask=mask)
582582

pandas/tests/extension/base/groupby.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def test_in_numeric_groupby(self, data_for_grouping):
163163
msg = "|".join(
164164
[
165165
# period/datetime
166-
"does not support sum operations",
166+
"does not support operation: 'sum'",
167167
# all others
168168
re.escape(f"agg function failed [how->sum,dtype->{dtype}"),
169169
]

pandas/tests/extension/test_datetime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def _supports_reduction(self, obj, op_name: str) -> bool:
104104
@pytest.mark.parametrize("skipna", [True, False])
105105
def test_reduce_series_boolean(self, data, all_boolean_reductions, skipna):
106106
meth = all_boolean_reductions
107-
msg = f"datetime64 type does not support {meth} operations"
107+
msg = f"datetime64 type does not support operation: '{meth}'"
108108
with pytest.raises(TypeError, match=msg):
109109
super().test_reduce_series_boolean(data, all_boolean_reductions, skipna)
110110

pandas/tests/frame/test_reductions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,7 @@ def test_any_datetime(self):
13821382
]
13831383
df = DataFrame({"A": float_data, "B": datetime_data})
13841384

1385-
msg = "datetime64 type does not support any operations"
1385+
msg = "datetime64 type does not support operation: 'any'"
13861386
with pytest.raises(TypeError, match=msg):
13871387
df.any(axis=1)
13881388

@@ -1478,7 +1478,7 @@ def test_any_all_np_func(self, func, data, expected):
14781478
getattr(DataFrame(data), func.__name__)(axis=None)
14791479
if data.dtypes.apply(lambda x: x.kind == "M").any():
14801480
# GH#34479
1481-
msg = "datetime64 type does not support (any|all) operations"
1481+
msg = "datetime64 type does not support operation: '(any|all)'"
14821482
with pytest.raises(TypeError, match=msg):
14831483
func(data)
14841484

pandas/tests/groupby/test_groupby.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ def test_raises_on_nuisance(df):
674674
df = df.loc[:, ["A", "C", "D"]]
675675
df["E"] = datetime.now()
676676
grouped = df.groupby("A")
677-
msg = "datetime64 type does not support sum operations"
677+
msg = "datetime64 type does not support operation: 'sum'"
678678
with pytest.raises(TypeError, match=msg):
679679
grouped.agg("sum")
680680
with pytest.raises(TypeError, match=msg):

pandas/tests/groupby/test_raises.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -241,16 +241,16 @@ def test_groupby_raises_datetime(
241241
return
242242

243243
klass, msg = {
244-
"all": (TypeError, "datetime64 type does not support all operations"),
245-
"any": (TypeError, "datetime64 type does not support any operations"),
244+
"all": (TypeError, "datetime64 type does not support operation: 'all'"),
245+
"any": (TypeError, "datetime64 type does not support operation: 'any'"),
246246
"bfill": (None, ""),
247247
"corrwith": (TypeError, "cannot perform __mul__ with this index type"),
248248
"count": (None, ""),
249249
"cumcount": (None, ""),
250250
"cummax": (None, ""),
251251
"cummin": (None, ""),
252-
"cumprod": (TypeError, "datetime64 type does not support cumprod operations"),
253-
"cumsum": (TypeError, "datetime64 type does not support cumsum operations"),
252+
"cumprod": (TypeError, "datetime64 type does not support operation: 'cumprod'"),
253+
"cumsum": (TypeError, "datetime64 type does not support operation: 'cumsum'"),
254254
"diff": (None, ""),
255255
"ffill": (None, ""),
256256
"fillna": (None, ""),
@@ -265,7 +265,7 @@ def test_groupby_raises_datetime(
265265
"ngroup": (None, ""),
266266
"nunique": (None, ""),
267267
"pct_change": (TypeError, "cannot perform __truediv__ with this index type"),
268-
"prod": (TypeError, "datetime64 type does not support prod"),
268+
"prod": (TypeError, "datetime64 type does not support operation: 'prod'"),
269269
"quantile": (None, ""),
270270
"rank": (None, ""),
271271
"sem": (None, ""),
@@ -276,13 +276,13 @@ def test_groupby_raises_datetime(
276276
"|".join(
277277
[
278278
r"dtype datetime64\[ns\] does not support reduction",
279-
"datetime64 type does not support skew operations",
279+
"datetime64 type does not support operation: 'skew'",
280280
]
281281
),
282282
),
283283
"std": (None, ""),
284-
"sum": (TypeError, "datetime64 type does not support sum operations"),
285-
"var": (TypeError, "datetime64 type does not support var operations"),
284+
"sum": (TypeError, "datetime64 type does not support operation: 'sum"),
285+
"var": (TypeError, "datetime64 type does not support operation: 'var'"),
286286
}[groupby_func]
287287

288288
if groupby_func == "fillna":

pandas/tests/reductions/test_reductions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ def test_any_all_datetimelike(self):
10101010
df = DataFrame(ser)
10111011

10121012
# GH#34479
1013-
msg = "datetime64 type does not support (any|all) operations"
1013+
msg = "datetime64 type does not support operation: '(any|all)'"
10141014
with pytest.raises(TypeError, match=msg):
10151015
dta.all()
10161016
with pytest.raises(TypeError, match=msg):

pandas/tests/resample/test_resample_api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,9 @@ def test_selection_api_validation():
708708
tm.assert_frame_equal(exp, result)
709709

710710
exp.index.name = "d"
711-
with pytest.raises(TypeError, match="datetime64 type does not support sum"):
711+
with pytest.raises(
712+
TypeError, match="datetime64 type does not support operation: 'sum'"
713+
):
712714
df.resample("2D", level="d").sum()
713715
result = df.resample("2D", level="d").sum(numeric_only=True)
714716
tm.assert_frame_equal(exp, result)

0 commit comments

Comments
 (0)