Repository: pandas-dev/pandas

Issue:
Revert changes to comparison between Series[datetime64ns] and datetime.date
Revert the changes in https://github.com/pandas-dev/pandas/pull/21361

- [ ]: Remove check in `core/ops.py`
- [ ]: Remove test `pandas/tests/tseries/test_arithmetic.py::TestTimestampSeriesComparison.test_dt64_ser_cmp_date_warning`
- [ ]: Reenable test `pandas/tests/tseries/test_arithmetic.py::TestTimestampSeriesComparison.test_dt64ser_cmp_date_invalid`

Target this for 0.24?

xref https://github.com/pandas-dev/pandas/issues/21152



Discussion:
@jreback @jorisvandenbossche can we do this for 0.24.0? That would mean

- `<0.22` : compare equal
- `0.23.0` : compare unequal
- `>=0.23.1,<0.24.0` : compare equal & warn
- `0.24.0` : compare unequal
that looks good to me
We typically have deprecations for longer than a single release. Is there a good reason to not do that here? 
(it's not that the current situation is actively harmful or so)
If this were the behavior in 0.23.0, I would agree with a longer deprecation cycle. Should the fact that 0.23.0 and 0.23.1 behave differently change our thoughts at all? (I'm not sure really)
I don't think that that is a reason to have a shorter deprecation cycle (at least it does not give any problems with the different behaviour, as if you already changed your code to the correct way when using 0.23.0, this will also work for the later versions with the reverted comparison op)
That's fair.

On Fri, Jun 8, 2018 at 10:59 AM, Joris Van den Bossche <
notifications@github.com> wrote:

> I don't think that that is a reason to have a shorter deprecation cycle
> (at least it does not give any problems with the different behaviour, as if
> you already changed your code to the correct way when using 0.23.0, this
> will also work for the later versions with the reverted comparison op)
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/issues/21359#issuecomment-395806617>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABQHIlBRaAra-hbD9FiTCLQ1wmZhaB_rks5t6p9KgaJpZM4Ue0H->
> .
>

https://github.com/pandas-dev/pandas/issues/21359#issuecomment-395749008 looks like the plan was to implement the new behavior in 0.24.0.  Any objection to doing it now?

Resolving patch:
diff --git a/pandas/core/ops/__init__.py b/pandas/core/ops/__init__.py
--- 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):


Test patch:
diff --git a/pandas/tests/arithmetic/test_datetime64.py b/pandas/tests/arithmetic/test_datetime64.py
--- 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):