Skip to content

Commit 7039f6a

Browse files
jbrockmendelTomAugspurger
authored andcommitted
DEPR: remove deprecated date casting; closes #21359 (#27109)
* DEPR: remove deprecated date casting; closes #21359
1 parent 313665a commit 7039f6a

File tree

3 files changed

+5
-69
lines changed

3 files changed

+5
-69
lines changed

doc/source/whatsnew/v0.25.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,7 @@ Removal of prior version deprecations/changes
974974
- Removed the previously deprecated ``cdate_range`` (:issue:`17691`)
975975
- Removed the previously deprecated ``True`` option for the ``dropna`` keyword argument in :func:`SeriesGroupBy.nth` (:issue:`17493`)
976976
- Removed the previously deprecated ``convert`` keyword argument in :meth:`Series.take` and :meth:`DataFrame.take` (:issue:`17352`)
977+
- Removed the previously deprecated behavior of arithmetic operations with ``datetime.date`` objects (:issue:`21152`)
977978
978979
.. _whatsnew_0250.performance:
979980

pandas/core/ops/__init__.py

+1-27
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
"""
66
import datetime
77
import operator
8-
import textwrap
98
from typing import Any, Callable
10-
import warnings
119

1210
import numpy as np
1311

14-
from pandas._libs import Timedelta, Timestamp, lib, ops as libops
12+
from pandas._libs import Timedelta, lib, ops as libops
1513
from pandas.errors import NullFrequencyError
1614
from pandas.util._decorators import Appender
1715

@@ -1150,32 +1148,8 @@ def wrapper(self, other, axis=None):
11501148
elif is_datetime64_dtype(self) or is_datetime64tz_dtype(self):
11511149
# Dispatch to DatetimeIndex to ensure identical
11521150
# Series/Index behavior
1153-
if isinstance(other, datetime.date) and not isinstance(
1154-
other, datetime.datetime
1155-
):
1156-
# https://github.com/pandas-dev/pandas/issues/21152
1157-
# Compatibility for difference between Series comparison w/
1158-
# datetime and date
1159-
msg = (
1160-
"Comparing Series of datetimes with 'datetime.date'. "
1161-
"Currently, the 'datetime.date' is coerced to a "
1162-
"datetime. In the future pandas will not coerce, "
1163-
"and {future}. "
1164-
"To retain the current behavior, "
1165-
"convert the 'datetime.date' to a datetime with "
1166-
"'pd.Timestamp'."
1167-
)
1168-
1169-
if op in {operator.lt, operator.le, operator.gt, operator.ge}:
1170-
future = "a TypeError will be raised"
1171-
else:
1172-
future = "'the values will not compare equal to the 'datetime.date'"
1173-
msg = "\n".join(textwrap.wrap(msg.format(future=future)))
1174-
warnings.warn(msg, FutureWarning, stacklevel=2)
1175-
other = Timestamp(other)
11761151

11771152
res_values = dispatch_to_index_op(op, self, other, pd.DatetimeIndex)
1178-
11791153
return self._constructor(res_values, index=self.index, name=res_name)
11801154

11811155
elif is_timedelta64_dtype(self):

pandas/tests/arithmetic/test_datetime64.py

+3-42
Original file line numberDiff line numberDiff line change
@@ -227,56 +227,17 @@ def test_series_comparison_scalars(self):
227227
expected = Series([x > val for x in series])
228228
tm.assert_series_equal(result, expected)
229229

230-
def test_dt64_ser_cmp_date_warning(self):
231-
# https://github.com/pandas-dev/pandas/issues/21359
232-
# Remove this test and enble invalid test below
233-
ser = pd.Series(pd.date_range("20010101", periods=10), name="dates")
234-
date = ser.iloc[0].to_pydatetime().date()
235-
236-
with tm.assert_produces_warning(FutureWarning) as m:
237-
result = ser == date
238-
expected = pd.Series([True] + [False] * 9, name="dates")
239-
tm.assert_series_equal(result, expected)
240-
assert "Comparing Series of datetimes " in str(m[0].message)
241-
assert "will not compare equal" in str(m[0].message)
242-
243-
with tm.assert_produces_warning(FutureWarning) as m:
244-
result = ser != date
245-
tm.assert_series_equal(result, ~expected)
246-
assert "will not compare equal" in str(m[0].message)
247-
248-
with tm.assert_produces_warning(FutureWarning) as m:
249-
result = ser <= date
250-
tm.assert_series_equal(result, expected)
251-
assert "a TypeError will be raised" in str(m[0].message)
252-
253-
with tm.assert_produces_warning(FutureWarning) as m:
254-
result = ser < date
255-
tm.assert_series_equal(result, pd.Series([False] * 10, name="dates"))
256-
assert "a TypeError will be raised" in str(m[0].message)
257-
258-
with tm.assert_produces_warning(FutureWarning) as m:
259-
result = ser >= date
260-
tm.assert_series_equal(result, pd.Series([True] * 10, name="dates"))
261-
assert "a TypeError will be raised" in str(m[0].message)
262-
263-
with tm.assert_produces_warning(FutureWarning) as m:
264-
result = ser > date
265-
tm.assert_series_equal(result, pd.Series([False] + [True] * 9, name="dates"))
266-
assert "a TypeError will be raised" in str(m[0].message)
267-
268-
@pytest.mark.skip(reason="GH#21359")
269230
def test_dt64ser_cmp_date_invalid(self, box_with_array):
270231
# GH#19800 datetime.date comparison raises to
271232
# match DatetimeIndex/Timestamp. This also matches the behavior
272233
# of stdlib datetime.datetime
273234

274235
ser = pd.date_range("20010101", periods=10)
275-
date = ser.iloc[0].to_pydatetime().date()
236+
date = ser[0].to_pydatetime().date()
276237

277238
ser = tm.box_expected(ser, box_with_array)
278-
assert not (ser == date).any()
279-
assert (ser != date).all()
239+
assert_all(~(ser == date))
240+
assert_all(ser != date)
280241
with pytest.raises(TypeError):
281242
ser > date
282243
with pytest.raises(TypeError):

0 commit comments

Comments
 (0)