Skip to content

Commit da8f19d

Browse files
committed
combine two if
1 parent 6ee04db commit da8f19d

File tree

6 files changed

+9
-12
lines changed

6 files changed

+9
-12
lines changed

pandas/core/arrays/datetimelike.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,11 +1661,8 @@ def _groupby_op(
16611661
dtype = self.dtype
16621662
if dtype.kind == "M":
16631663
# Adding/multiplying datetimes is not valid
1664-
if how in ["sum", "prod", "cumsum", "cumprod", "var", "skew"]:
1664+
if how in ["any", "all", "sum", "prod", "cumsum", "cumprod", "var", "skew"]:
16651665
raise TypeError(f"datetime64 type does not support {how} operations")
1666-
if how in ["any", "all"]:
1667-
# GH#34479
1668-
raise TypeError(f"'{how}' with datetime64 dtypes is not supported")
16691666

16701667
elif isinstance(dtype, PeriodDtype):
16711668
# 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("'any' with datetime64 dtypes is not supported")
523+
raise TypeError("datetime64 type does not support any operations")
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("'all' with datetime64 dtypes is not supported")
579+
raise TypeError("datetime64 type does not support all operations")
580580

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

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"'{meth}' with datetime64 dtypes is not supported"
107+
msg = f"datetime64 type does not support {meth} operations"
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 = "'any' with datetime64 dtypes is not supported"
1385+
msg = "datetime64 type does not support any operations"
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 = "'(any|all)' with datetime64 dtypes is not supported"
1481+
msg = "datetime64 type does not support (any|all) operations"
14821482
with pytest.raises(TypeError, match=msg):
14831483
func(data)
14841484

pandas/tests/groupby/test_raises.py

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

243243
klass, msg = {
244-
"all": (TypeError, "'all' with datetime64 dtypes is not supported"),
245-
"any": (TypeError, "'any' with datetime64 dtypes is not supported"),
244+
"all": (TypeError, "datetime64 type does not support all operations"),
245+
"any": (TypeError, "datetime64 type does not support any operations"),
246246
"bfill": (None, ""),
247247
"corrwith": (TypeError, "cannot perform __mul__ with this index type"),
248248
"count": (None, ""),

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 = "'(any|all)' with datetime64 dtypes is not supported"
1013+
msg = "datetime64 type does not support (any|all) operations"
10141014
with pytest.raises(TypeError, match=msg):
10151015
dta.all()
10161016
with pytest.raises(TypeError, match=msg):

0 commit comments

Comments
 (0)