Skip to content

Commit b0a478b

Browse files
committed
DEPR: remove deprecated date casting; closes pandas-dev#21359
1 parent 3a53954 commit b0a478b

File tree

2 files changed

+3
-71
lines changed

2 files changed

+3
-71
lines changed

pandas/core/ops.py

-28
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
"""
66
import datetime
77
import operator
8-
import textwrap
98
from typing import Dict, Optional
10-
import warnings
119

1210
import numpy as np
1311

@@ -1817,32 +1815,6 @@ def wrapper(self, other, axis=None):
18171815
elif is_datetime64_dtype(self) or is_datetime64tz_dtype(self):
18181816
# Dispatch to DatetimeIndex to ensure identical
18191817
# Series/Index behavior
1820-
if (isinstance(other, datetime.date) and
1821-
not isinstance(other, datetime.datetime)):
1822-
# https://github.com/pandas-dev/pandas/issues/21152
1823-
# Compatibility for difference between Series comparison w/
1824-
# datetime and date
1825-
msg = (
1826-
"Comparing Series of datetimes with 'datetime.date'. "
1827-
"Currently, the 'datetime.date' is coerced to a "
1828-
"datetime. In the future pandas will not coerce, "
1829-
"and {future}. "
1830-
"To retain the current behavior, "
1831-
"convert the 'datetime.date' to a datetime with "
1832-
"'pd.Timestamp'."
1833-
)
1834-
1835-
if op in {operator.lt, operator.le, operator.gt, operator.ge}:
1836-
future = "a TypeError will be raised"
1837-
else:
1838-
future = (
1839-
"'the values will not compare equal to the "
1840-
"'datetime.date'"
1841-
)
1842-
msg = '\n'.join(textwrap.wrap(msg.format(future=future)))
1843-
warnings.warn(msg, FutureWarning, stacklevel=2)
1844-
other = pd.Timestamp(other)
1845-
18461818
res_values = dispatch_to_index_op(op, self, other,
18471819
pd.DatetimeIndex)
18481820

pandas/tests/arithmetic/test_datetime64.py

+3-43
Original file line numberDiff line numberDiff line change
@@ -207,57 +207,17 @@ def test_series_comparison_scalars(self):
207207
expected = Series([x > val for x in series])
208208
tm.assert_series_equal(result, expected)
209209

210-
def test_dt64_ser_cmp_date_warning(self):
211-
# https://github.com/pandas-dev/pandas/issues/21359
212-
# Remove this test and enble invalid test below
213-
ser = pd.Series(pd.date_range('20010101', periods=10), name='dates')
214-
date = ser.iloc[0].to_pydatetime().date()
215-
216-
with tm.assert_produces_warning(FutureWarning) as m:
217-
result = ser == date
218-
expected = pd.Series([True] + [False] * 9, name='dates')
219-
tm.assert_series_equal(result, expected)
220-
assert "Comparing Series of datetimes " in str(m[0].message)
221-
assert "will not compare equal" in str(m[0].message)
222-
223-
with tm.assert_produces_warning(FutureWarning) as m:
224-
result = ser != date
225-
tm.assert_series_equal(result, ~expected)
226-
assert "will not compare equal" in str(m[0].message)
227-
228-
with tm.assert_produces_warning(FutureWarning) as m:
229-
result = ser <= date
230-
tm.assert_series_equal(result, expected)
231-
assert "a TypeError will be raised" in str(m[0].message)
232-
233-
with tm.assert_produces_warning(FutureWarning) as m:
234-
result = ser < date
235-
tm.assert_series_equal(result, pd.Series([False] * 10, name='dates'))
236-
assert "a TypeError will be raised" in str(m[0].message)
237-
238-
with tm.assert_produces_warning(FutureWarning) as m:
239-
result = ser >= date
240-
tm.assert_series_equal(result, pd.Series([True] * 10, name='dates'))
241-
assert "a TypeError will be raised" 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, pd.Series([False] + [True] * 9,
246-
name='dates'))
247-
assert "a TypeError will be raised" in str(m[0].message)
248-
249-
@pytest.mark.skip(reason="GH#21359")
250210
def test_dt64ser_cmp_date_invalid(self, box_with_array):
251211
# GH#19800 datetime.date comparison raises to
252212
# match DatetimeIndex/Timestamp. This also matches the behavior
253213
# of stdlib datetime.datetime
254214

255215
ser = pd.date_range('20010101', periods=10)
256-
date = ser.iloc[0].to_pydatetime().date()
216+
date = ser[0].to_pydatetime().date()
257217

258218
ser = tm.box_expected(ser, box_with_array)
259-
assert not (ser == date).any()
260-
assert (ser != date).all()
219+
assert_all(~(ser == date))
220+
assert_all(ser != date)
261221
with pytest.raises(TypeError):
262222
ser > date
263223
with pytest.raises(TypeError):

0 commit comments

Comments
 (0)