Skip to content

Commit

Permalink
DEPR: remove deprecated date casting; closes pandas-dev#21359
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel committed Jun 28, 2019
1 parent 3a53954 commit b0a478b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 71 deletions.
28 changes: 0 additions & 28 deletions pandas/core/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
"""
import datetime
import operator
import textwrap
from typing import Dict, Optional
import warnings

import numpy as np

Expand Down Expand Up @@ -1817,32 +1815,6 @@ def wrapper(self, other, axis=None):
elif is_datetime64_dtype(self) or is_datetime64tz_dtype(self):
# Dispatch to DatetimeIndex to ensure identical
# Series/Index behavior
if (isinstance(other, datetime.date) and
not isinstance(other, datetime.datetime)):
# https://github.com/pandas-dev/pandas/issues/21152
# Compatibility for difference between Series comparison w/
# datetime and date
msg = (
"Comparing Series of datetimes with 'datetime.date'. "
"Currently, the 'datetime.date' is coerced to a "
"datetime. In the future pandas will not coerce, "
"and {future}. "
"To retain the current behavior, "
"convert the 'datetime.date' to a datetime with "
"'pd.Timestamp'."
)

if op in {operator.lt, operator.le, operator.gt, operator.ge}:
future = "a TypeError will be raised"
else:
future = (
"'the values will not compare equal to the "
"'datetime.date'"
)
msg = '\n'.join(textwrap.wrap(msg.format(future=future)))
warnings.warn(msg, FutureWarning, stacklevel=2)
other = pd.Timestamp(other)

res_values = dispatch_to_index_op(op, self, other,
pd.DatetimeIndex)

Expand Down
46 changes: 3 additions & 43 deletions pandas/tests/arithmetic/test_datetime64.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,57 +207,17 @@ def test_series_comparison_scalars(self):
expected = Series([x > val for x in series])
tm.assert_series_equal(result, expected)

def test_dt64_ser_cmp_date_warning(self):
# https://github.com/pandas-dev/pandas/issues/21359
# Remove this test and enble invalid test below
ser = pd.Series(pd.date_range('20010101', periods=10), name='dates')
date = ser.iloc[0].to_pydatetime().date()

with tm.assert_produces_warning(FutureWarning) as m:
result = ser == date
expected = pd.Series([True] + [False] * 9, name='dates')
tm.assert_series_equal(result, expected)
assert "Comparing Series of datetimes " in str(m[0].message)
assert "will not compare equal" in str(m[0].message)

with tm.assert_produces_warning(FutureWarning) as m:
result = ser != date
tm.assert_series_equal(result, ~expected)
assert "will not compare equal" in str(m[0].message)

with tm.assert_produces_warning(FutureWarning) as m:
result = ser <= date
tm.assert_series_equal(result, expected)
assert "a TypeError will be raised" in str(m[0].message)

with tm.assert_produces_warning(FutureWarning) as m:
result = ser < date
tm.assert_series_equal(result, pd.Series([False] * 10, name='dates'))
assert "a TypeError will be raised" in str(m[0].message)

with tm.assert_produces_warning(FutureWarning) as m:
result = ser >= date
tm.assert_series_equal(result, pd.Series([True] * 10, name='dates'))
assert "a TypeError will be raised" in str(m[0].message)

with tm.assert_produces_warning(FutureWarning) as m:
result = ser > date
tm.assert_series_equal(result, pd.Series([False] + [True] * 9,
name='dates'))
assert "a TypeError will be raised" in str(m[0].message)

@pytest.mark.skip(reason="GH#21359")
def test_dt64ser_cmp_date_invalid(self, box_with_array):
# GH#19800 datetime.date comparison raises to
# match DatetimeIndex/Timestamp. This also matches the behavior
# of stdlib datetime.datetime

ser = pd.date_range('20010101', periods=10)
date = ser.iloc[0].to_pydatetime().date()
date = ser[0].to_pydatetime().date()

ser = tm.box_expected(ser, box_with_array)
assert not (ser == date).any()
assert (ser != date).all()
assert_all(~(ser == date))
assert_all(ser != date)
with pytest.raises(TypeError):
ser > date
with pytest.raises(TypeError):
Expand Down

0 comments on commit b0a478b

Please sign in to comment.