From ce983c387297a30b1d10205c92d61c4d854db20a Mon Sep 17 00:00:00 2001 From: Yuanhao Geng <41546976+GYHHAHA@users.noreply.github.com> Date: Sat, 26 Sep 2020 18:23:52 +0800 Subject: [PATCH 1/8] deprecate DateOffset args don't end in 's' also raise for nanosecond(s) argument in DateOffset --- pandas/_libs/tslibs/offsets.pyx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 161e5f4e54f51..8b25e4f2a7b46 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -300,16 +300,30 @@ cdef _determine_offset(kwds): # timedelta is used for sub-daily plural offsets and all singular # offsets relativedelta is used for plural offsets of daily length or # more nanosecond(s) are handled by apply_wraps + + if any(k in ('nanosecond', 'nanoseconds') for k in kwds.keys()): + raise ValueError("Argument nanosecond(s) is not allowed in " + "DateOffset, use offsets.Nano or nanosecond " + "in Timedelta instead.") + kwds_no_nanos = dict( (k, v) for k, v in kwds.items() if k not in ('nanosecond', 'nanoseconds') ) - # TODO: Are nanosecond and nanoseconds allowed somewhere? _kwds_use_relativedelta = ('years', 'months', 'weeks', 'days', 'year', 'month', 'week', 'day', 'weekday', 'hour', 'minute', 'second', 'microsecond') + if any(not k.endswith('s') for k in kwds_no_nanos): + warnings.warn( + "The DateOffset arguments that do not end in 's' replace " + "the offset value instead of making an addition. They are " + "deprecated now and slated for removal in the future.", + FutureWarning, + stacklevel=1, + ) + use_relativedelta = False if len(kwds_no_nanos) > 0: if any(k in _kwds_use_relativedelta for k in kwds_no_nanos): From 880d9dfd862143304dd3851fc9b4cd1c22b11b8b Mon Sep 17 00:00:00 2001 From: Yuanhao Geng <41546976+GYHHAHA@users.noreply.github.com> Date: Sat, 26 Sep 2020 21:02:57 +0800 Subject: [PATCH 2/8] Update offsets.pyx --- pandas/_libs/tslibs/offsets.pyx | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 8b25e4f2a7b46..38ce7510c9226 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -301,15 +301,11 @@ cdef _determine_offset(kwds): # offsets relativedelta is used for plural offsets of daily length or # more nanosecond(s) are handled by apply_wraps - if any(k in ('nanosecond', 'nanoseconds') for k in kwds.keys()): - raise ValueError("Argument nanosecond(s) is not allowed in " - "DateOffset, use offsets.Nano or nanosecond " - "in Timedelta instead.") - kwds_no_nanos = dict( (k, v) for k, v in kwds.items() if k not in ('nanosecond', 'nanoseconds') ) + # TODO: Are nanosecond and nanoseconds allowed somewhere? _kwds_use_relativedelta = ('years', 'months', 'weeks', 'days', 'year', 'month', 'week', 'day', 'weekday', @@ -322,7 +318,7 @@ cdef _determine_offset(kwds): "deprecated now and slated for removal in the future.", FutureWarning, stacklevel=1, - ) + ) use_relativedelta = False if len(kwds_no_nanos) > 0: From c248877ffb57abf2c06ef37eae64a84a21c70393 Mon Sep 17 00:00:00 2001 From: Yuanhao Geng <41546976+GYHHAHA@users.noreply.github.com> Date: Sat, 26 Sep 2020 21:04:20 +0800 Subject: [PATCH 3/8] Update offsets.pyx --- pandas/_libs/tslibs/offsets.pyx | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 38ce7510c9226..be7e611f83b56 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -300,7 +300,6 @@ cdef _determine_offset(kwds): # timedelta is used for sub-daily plural offsets and all singular # offsets relativedelta is used for plural offsets of daily length or # more nanosecond(s) are handled by apply_wraps - kwds_no_nanos = dict( (k, v) for k, v in kwds.items() if k not in ('nanosecond', 'nanoseconds') From dcca70bc0d4e44c928c68c6835787b6c9c20900f Mon Sep 17 00:00:00 2001 From: Yuanhao Geng <41546976+GYHHAHA@users.noreply.github.com> Date: Sat, 26 Sep 2020 21:41:28 +0800 Subject: [PATCH 4/8] Update offsets.pyx --- pandas/_libs/tslibs/offsets.pyx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index be7e611f83b56..87632984133f3 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -312,11 +312,11 @@ cdef _determine_offset(kwds): if any(not k.endswith('s') for k in kwds_no_nanos): warnings.warn( - "The DateOffset arguments that do not end in 's' replace " - "the offset value instead of making an addition. They are " - "deprecated now and slated for removal in the future.", - FutureWarning, - stacklevel=1, + "The DateOffset arguments that do not end in 's' replace " + "the offset value instead of making an addition. They are " + "deprecated now and slated for removal in the future.", + FutureWarning, + stacklevel=1, ) use_relativedelta = False From 947a7e432a8136530e0bf2e5683182a664812e1d Mon Sep 17 00:00:00 2001 From: Yuanhao Geng <41546976+GYHHAHA@users.noreply.github.com> Date: Sun, 27 Sep 2020 13:41:07 +0800 Subject: [PATCH 5/8] add weekday permission --- pandas/_libs/tslibs/offsets.pyx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 87632984133f3..c34a9b2e87811 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -311,13 +311,14 @@ cdef _determine_offset(kwds): 'hour', 'minute', 'second', 'microsecond') if any(not k.endswith('s') for k in kwds_no_nanos): - warnings.warn( - "The DateOffset arguments that do not end in 's' replace " - "the offset value instead of making an addition. They are " - "deprecated now and slated for removal in the future.", - FutureWarning, - stacklevel=1, - ) + if 'weekday' not in kwds_no_nanos: + warnings.warn( + "The DateOffset arguments that do not end in 's' replace " + "the offset value instead of making an addition. They are " + "deprecated now and slated for removal in the future.", + FutureWarning, + stacklevel=1, + ) use_relativedelta = False if len(kwds_no_nanos) > 0: From 734524cda3a81da8aab1cb6575708464855d7d44 Mon Sep 17 00:00:00 2001 From: Yuanhao Geng <41546976+GYHHAHA@users.noreply.github.com> Date: Fri, 2 Oct 2020 09:57:15 +0800 Subject: [PATCH 6/8] change warning description --- pandas/_libs/tslibs/offsets.pyx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index c34a9b2e87811..91628483b3ddb 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -309,13 +309,14 @@ cdef _determine_offset(kwds): _kwds_use_relativedelta = ('years', 'months', 'weeks', 'days', 'year', 'month', 'week', 'day', 'weekday', 'hour', 'minute', 'second', 'microsecond') - + if any(not k.endswith('s') for k in kwds_no_nanos): if 'weekday' not in kwds_no_nanos: warnings.warn( - "The DateOffset arguments that do not end in 's' replace " - "the offset value instead of making an addition. They are " - "deprecated now and slated for removal in the future.", + "Date Offset arguments that do not end with 's' overwrites " + "the offset instead of incrementing it. These arguments " + "are deprecated now and slated for removal in a future " + "version.", FutureWarning, stacklevel=1, ) From 4ec684873ac6231e647bbd7023396a772ffcd590 Mon Sep 17 00:00:00 2001 From: Yuanhao Geng <41546976+GYHHAHA@users.noreply.github.com> Date: Fri, 2 Oct 2020 10:01:41 +0800 Subject: [PATCH 7/8] update 1.2.0 whatsnew --- doc/source/whatsnew/v1.2.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index 031c74b1cc367..704300f95a7d2 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -214,6 +214,7 @@ Deprecations - :meth:`DataFrame.lookup` is deprecated and will be removed in a future version, use :meth:`DataFrame.melt` and :meth:`DataFrame.loc` instead (:issue:`18682`) - The :meth:`Index.to_native_types` is deprecated. Use ``.astype(str)`` instead (:issue:`28867`) - Deprecated indexing :class:`DataFrame` rows with datetime-like strings ``df[string]``, use ``df.loc[string]`` instead (:issue:`36179`) +- Use of Date Offset arguments that do not end with 's' overwrites the offset instead of incrementing it. These arguments are deprecated now and slated for removal in a future version (:issue:`36660`) .. --------------------------------------------------------------------------- From 6d728ff095ae015ba562bae51913b2e3fdc41e90 Mon Sep 17 00:00:00 2001 From: Yuanhao Geng <41546976+GYHHAHA@users.noreply.github.com> Date: Fri, 2 Oct 2020 15:05:11 +0800 Subject: [PATCH 8/8] Update offsets.pyx --- pandas/_libs/tslibs/offsets.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index a656547a58913..2277e3da3a612 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -311,7 +311,7 @@ cdef _determine_offset(kwds): _kwds_use_relativedelta = ('years', 'months', 'weeks', 'days', 'year', 'month', 'week', 'day', 'weekday', 'hour', 'minute', 'second', 'microsecond') - + if any(not k.endswith('s') for k in kwds_no_nanos): if 'weekday' not in kwds_no_nanos: warnings.warn(