From dfb8e3ff9b48159b4f8bd88e60d5b506e4c9ed19 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 31 Jul 2019 12:50:27 -0700 Subject: [PATCH] DEPR: remove deprecated date casting; closes #21359 (#27109) * DEPR: remove deprecated date casting; closes #21359 --- doc/source/whatsnew/v0.25.0.rst | 1 + pandas/core/ops/__init__.py | 28 +------------- pandas/tests/arithmetic/test_datetime64.py | 45 ++-------------------- 3 files changed, 5 insertions(+), 69 deletions(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 42e756635e739..f4ef26dd8b740 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -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: diff --git a/pandas/core/ops/__init__.py b/pandas/core/ops/__init__.py index 3a5dfe6700bd2..a9d18c194889c 100644 --- a/pandas/core/ops/__init__.py +++ b/pandas/core/ops/__init__.py @@ -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 @@ -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): diff --git a/pandas/tests/arithmetic/test_datetime64.py b/pandas/tests/arithmetic/test_datetime64.py index 6037273450a1c..cca6836acf626 100644 --- a/pandas/tests/arithmetic/test_datetime64.py +++ b/pandas/tests/arithmetic/test_datetime64.py @@ -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):