From b0a478ba70b7cd7c0df5741fe023df0988f4c0a1 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Fri, 28 Jun 2019 16:40:16 -0500 Subject: [PATCH 1/3] DEPR: remove deprecated date casting; closes #21359 --- pandas/core/ops.py | 28 ------------- pandas/tests/arithmetic/test_datetime64.py | 46 ++-------------------- 2 files changed, 3 insertions(+), 71 deletions(-) diff --git a/pandas/core/ops.py b/pandas/core/ops.py index 0b9e56fd19556..ed6477d3ed9d7 100644 --- a/pandas/core/ops.py +++ b/pandas/core/ops.py @@ -5,9 +5,7 @@ """ import datetime import operator -import textwrap from typing import Dict, Optional -import warnings import numpy as np @@ -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) diff --git a/pandas/tests/arithmetic/test_datetime64.py b/pandas/tests/arithmetic/test_datetime64.py index b1091d38c10d0..d10e1b00e8e4e 100644 --- a/pandas/tests/arithmetic/test_datetime64.py +++ b/pandas/tests/arithmetic/test_datetime64.py @@ -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): From 842080a73974c53d9efb4f0ce802529d7f2efaf1 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Fri, 28 Jun 2019 16:44:34 -0500 Subject: [PATCH 2/3] whatsnew note --- doc/source/whatsnew/v0.25.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 1fe808e098860..039df83b83dc2 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -616,6 +616,7 @@ Removal of prior version deprecations/changes - Removed the previously deprecated ``pd.options.html.border`` (:issue:`16970`) - Removed the previously deprecated ``convert_objects`` (:issue:`11221`) - Removed the previously deprecated ``select`` method of ``DataFrame`` and ``Series`` (:issue:`17633`) +- Removed the previously deprecated behavior of arithmetic operations with ``datetime.date`` objects (:issue:`21152`) .. _whatsnew_0250.performance: From fa402d7ee25ee14e956bf62e3fd01997df2a8e97 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Fri, 19 Jul 2019 18:15:55 -0700 Subject: [PATCH 3/3] remove unused import --- pandas/core/ops/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/ops/__init__.py b/pandas/core/ops/__init__.py index 2c4653409231e..b6b6ce7a9d20a 100644 --- a/pandas/core/ops/__init__.py +++ b/pandas/core/ops/__init__.py @@ -9,7 +9,7 @@ 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