Skip to content

Commit

Permalink
DEPR: remove deprecated date casting; closes pandas-dev#21359 (pandas…
Browse files Browse the repository at this point in the history
…-dev#27109)

* DEPR: remove deprecated date casting; closes pandas-dev#21359
  • Loading branch information
jbrockmendel authored and quintusdias committed Aug 15, 2019
1 parent 2a1b112 commit dfb8e3f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 69 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,7 @@ Removal of prior version deprecations/changes
- Removed the previously deprecated ``cdate_range`` (:issue:`17691`)
- Removed the previously deprecated ``True`` option for the ``dropna`` keyword argument in :func:`SeriesGroupBy.nth` (:issue:`17493`)
- Removed the previously deprecated ``convert`` keyword argument in :meth:`Series.take` and :meth:`DataFrame.take` (:issue:`17352`)
- Removed the previously deprecated behavior of arithmetic operations with ``datetime.date`` objects (:issue:`21152`)
.. _whatsnew_0250.performance:
Expand Down
28 changes: 1 addition & 27 deletions pandas/core/ops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
"""
import datetime
import operator
import textwrap
from typing import Any, Callable
import warnings

import numpy as np

from pandas._libs import Timedelta, Timestamp, lib, ops as libops
from pandas._libs import Timedelta, lib, ops as libops
from pandas.errors import NullFrequencyError
from pandas.util._decorators import Appender

Expand Down Expand Up @@ -1150,32 +1148,8 @@ 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 = Timestamp(other)

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

return self._constructor(res_values, index=self.index, name=res_name)

elif is_timedelta64_dtype(self):
Expand Down
45 changes: 3 additions & 42 deletions pandas/tests/arithmetic/test_datetime64.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,56 +227,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 dfb8e3f

Please sign in to comment.