From ea8a773ea7e5bf2f13e8ce2b34b4c0d23318fda6 Mon Sep 17 00:00:00 2001 From: Yuanhao Geng <41546976+GYHHAHA@users.noreply.github.com> Date: Mon, 21 Sep 2020 12:17:34 +0800 Subject: [PATCH 01/12] Update timeseries.rst correct inconsistent doc description on default DateOffset setting --- doc/source/user_guide/timeseries.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/source/user_guide/timeseries.rst b/doc/source/user_guide/timeseries.rst index 32f0cac3f81e2..028cc4cbfbc7f 100644 --- a/doc/source/user_guide/timeseries.rst +++ b/doc/source/user_guide/timeseries.rst @@ -831,6 +831,8 @@ arithmetic operator (``+``) or the ``apply`` method can be used to perform the s ts + pd.Timedelta(days=1) # Respects calendar time ts + pd.DateOffset(days=1) + # Default DateOffset is 24 hours instead of a calendar day since Hour is one of subclasses for DateOffset + ts + pd.DateOffset() friday = pd.Timestamp('2018-01-05') friday.day_name() # Add 2 business days (Friday --> Tuesday) @@ -846,7 +848,7 @@ into ``freq`` keyword arguments. The available date offsets and associated frequ :header: "Date Offset", "Frequency String", "Description" :widths: 15, 15, 65 - :class:`~pandas.tseries.offsets.DateOffset`, None, "Generic offset class, defaults to 1 calendar day" + :class:`~pandas.tseries.offsets.DateOffset`, None, "Generic offset class, defaults to 24 hours" :class:`~pandas.tseries.offsets.BDay` or :class:`~pandas.tseries.offsets.BusinessDay`, ``'B'``,"business day (weekday)" :class:`~pandas.tseries.offsets.CDay` or :class:`~pandas.tseries.offsets.CustomBusinessDay`, ``'C'``, "custom business day" :class:`~pandas.tseries.offsets.Week`, ``'W'``, "one week, optionally anchored on a day of the week" From 8a07c3a38125b7622863c21cb980b2df0682db47 Mon Sep 17 00:00:00 2001 From: Yuanhao Geng <41546976+GYHHAHA@users.noreply.github.com> Date: Mon, 21 Sep 2020 12:47:30 +0800 Subject: [PATCH 02/12] Update timeseries.rst remove the example for DateOffset default setting --- doc/source/user_guide/timeseries.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/doc/source/user_guide/timeseries.rst b/doc/source/user_guide/timeseries.rst index 028cc4cbfbc7f..5d5403f1e236b 100644 --- a/doc/source/user_guide/timeseries.rst +++ b/doc/source/user_guide/timeseries.rst @@ -831,8 +831,6 @@ arithmetic operator (``+``) or the ``apply`` method can be used to perform the s ts + pd.Timedelta(days=1) # Respects calendar time ts + pd.DateOffset(days=1) - # Default DateOffset is 24 hours instead of a calendar day since Hour is one of subclasses for DateOffset - ts + pd.DateOffset() friday = pd.Timestamp('2018-01-05') friday.day_name() # Add 2 business days (Friday --> Tuesday) From 90d4f8a856ae4cb12e1bbd1baaf240f77586e694 Mon Sep 17 00:00:00 2001 From: Yuanhao Geng <41546976+GYHHAHA@users.noreply.github.com> Date: Tue, 22 Sep 2020 09:21:39 +0800 Subject: [PATCH 03/12] Update offsets.pyx Change the default setting for DateOffset to a calendar day. --- pandas/_libs/tslibs/offsets.pyx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 161e5f4e54f51..055ceee1ac56e 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -319,7 +319,8 @@ cdef _determine_offset(kwds): # sub-daily offset - use timedelta (tz-aware) offset = timedelta(**kwds_no_nanos) else: - offset = timedelta(1) + offset = relativedelta(**{'days':1}) + use_relativedelta = True return offset, use_relativedelta From eeb89c6310a02a668ce2691312852bdf89738c0b Mon Sep 17 00:00:00 2001 From: Yuanhao Geng <41546976+GYHHAHA@users.noreply.github.com> Date: Tue, 22 Sep 2020 09:30:28 +0800 Subject: [PATCH 04/12] Update test_liboffsets.py add a test for dateoffset default value --- pandas/tests/tslibs/test_liboffsets.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pandas/tests/tslibs/test_liboffsets.py b/pandas/tests/tslibs/test_liboffsets.py index 6a514d2cc8713..9f1bb56000406 100644 --- a/pandas/tests/tslibs/test_liboffsets.py +++ b/pandas/tests/tslibs/test_liboffsets.py @@ -168,3 +168,9 @@ def test_roll_qtr_day_mod_equal(other, month, exp_dict, n, day_opt): @pytest.mark.parametrize("compare", [29, 1, 31]) def test_roll_convention(n, expected, compare): assert liboffsets.roll_convention(29, n, compare) == expected[compare] + +def test_default_value_for_dateoffset_is_a_calender_day(): + #36516 + ts = Timestamp('2011-3-27 00:00:00', tz='Europe/Helsinki') + expected = ts + liboffsets.DateOffset(days=1) + assert ts + liboffsets.DateOffset() == expected From 0d5e1a3b25f3390eee2d9b215785f98832d6a9eb Mon Sep 17 00:00:00 2001 From: Yuanhao Geng <41546976+GYHHAHA@users.noreply.github.com> Date: Tue, 22 Sep 2020 09:32:25 +0800 Subject: [PATCH 05/12] Update timeseries.rst change doc to original description --- doc/source/user_guide/timeseries.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/user_guide/timeseries.rst b/doc/source/user_guide/timeseries.rst index 5d5403f1e236b..1088ff28ebf50 100644 --- a/doc/source/user_guide/timeseries.rst +++ b/doc/source/user_guide/timeseries.rst @@ -846,7 +846,7 @@ into ``freq`` keyword arguments. The available date offsets and associated frequ :header: "Date Offset", "Frequency String", "Description" :widths: 15, 15, 65 - :class:`~pandas.tseries.offsets.DateOffset`, None, "Generic offset class, defaults to 24 hours" + :class:`~pandas.tseries.offsets.DateOffset`, None, "Generic offset class, defaults to a calendar day" :class:`~pandas.tseries.offsets.BDay` or :class:`~pandas.tseries.offsets.BusinessDay`, ``'B'``,"business day (weekday)" :class:`~pandas.tseries.offsets.CDay` or :class:`~pandas.tseries.offsets.CustomBusinessDay`, ``'C'``, "custom business day" :class:`~pandas.tseries.offsets.Week`, ``'W'``, "one week, optionally anchored on a day of the week" From f245260d502536b5c0bd8d8f713c5f89639b456f Mon Sep 17 00:00:00 2001 From: Yuanhao Geng <41546976+GYHHAHA@users.noreply.github.com> Date: Tue, 22 Sep 2020 09:38:17 +0800 Subject: [PATCH 06/12] Update test_liboffsets.py resolve PEP 8 issues --- pandas/tests/tslibs/test_liboffsets.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/tslibs/test_liboffsets.py b/pandas/tests/tslibs/test_liboffsets.py index 9f1bb56000406..d74bc184f9a65 100644 --- a/pandas/tests/tslibs/test_liboffsets.py +++ b/pandas/tests/tslibs/test_liboffsets.py @@ -169,8 +169,9 @@ def test_roll_qtr_day_mod_equal(other, month, exp_dict, n, day_opt): def test_roll_convention(n, expected, compare): assert liboffsets.roll_convention(29, n, compare) == expected[compare] + def test_default_value_for_dateoffset_is_a_calender_day(): - #36516 + # 36516 ts = Timestamp('2011-3-27 00:00:00', tz='Europe/Helsinki') expected = ts + liboffsets.DateOffset(days=1) assert ts + liboffsets.DateOffset() == expected From 2399eb8d2f0b7ba252ae35aee1f74f44f6676c6b Mon Sep 17 00:00:00 2001 From: Yuanhao Geng <41546976+GYHHAHA@users.noreply.github.com> Date: Tue, 22 Sep 2020 14:41:59 +0800 Subject: [PATCH 07/12] Update timeseries.rst --- doc/source/user_guide/timeseries.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/user_guide/timeseries.rst b/doc/source/user_guide/timeseries.rst index 1088ff28ebf50..32f0cac3f81e2 100644 --- a/doc/source/user_guide/timeseries.rst +++ b/doc/source/user_guide/timeseries.rst @@ -846,7 +846,7 @@ into ``freq`` keyword arguments. The available date offsets and associated frequ :header: "Date Offset", "Frequency String", "Description" :widths: 15, 15, 65 - :class:`~pandas.tseries.offsets.DateOffset`, None, "Generic offset class, defaults to a calendar day" + :class:`~pandas.tseries.offsets.DateOffset`, None, "Generic offset class, defaults to 1 calendar day" :class:`~pandas.tseries.offsets.BDay` or :class:`~pandas.tseries.offsets.BusinessDay`, ``'B'``,"business day (weekday)" :class:`~pandas.tseries.offsets.CDay` or :class:`~pandas.tseries.offsets.CustomBusinessDay`, ``'C'``, "custom business day" :class:`~pandas.tseries.offsets.Week`, ``'W'``, "one week, optionally anchored on a day of the week" From bc0a02e1f357233e26d584eecb2931f60ade06a0 Mon Sep 17 00:00:00 2001 From: Yuanhao Geng <41546976+GYHHAHA@users.noreply.github.com> Date: Thu, 24 Sep 2020 09:21:46 +0800 Subject: [PATCH 08/12] Update test_liboffsets.py --- pandas/tests/tslibs/test_liboffsets.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/pandas/tests/tslibs/test_liboffsets.py b/pandas/tests/tslibs/test_liboffsets.py index d74bc184f9a65..6a514d2cc8713 100644 --- a/pandas/tests/tslibs/test_liboffsets.py +++ b/pandas/tests/tslibs/test_liboffsets.py @@ -168,10 +168,3 @@ def test_roll_qtr_day_mod_equal(other, month, exp_dict, n, day_opt): @pytest.mark.parametrize("compare", [29, 1, 31]) def test_roll_convention(n, expected, compare): assert liboffsets.roll_convention(29, n, compare) == expected[compare] - - -def test_default_value_for_dateoffset_is_a_calender_day(): - # 36516 - ts = Timestamp('2011-3-27 00:00:00', tz='Europe/Helsinki') - expected = ts + liboffsets.DateOffset(days=1) - assert ts + liboffsets.DateOffset() == expected From a8b3189e24dcc0e25153235304f442515ac4add2 Mon Sep 17 00:00:00 2001 From: Yuanhao Geng <41546976+GYHHAHA@users.noreply.github.com> Date: Thu, 24 Sep 2020 09:22:57 +0800 Subject: [PATCH 09/12] Update offsets.pyx --- pandas/_libs/tslibs/offsets.pyx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 055ceee1ac56e..161e5f4e54f51 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -319,8 +319,7 @@ cdef _determine_offset(kwds): # sub-daily offset - use timedelta (tz-aware) offset = timedelta(**kwds_no_nanos) else: - offset = relativedelta(**{'days':1}) - use_relativedelta = True + offset = timedelta(1) return offset, use_relativedelta From dca455a1f3cdfc1211ddc0c078b7eb753fa74790 Mon Sep 17 00:00:00 2001 From: Yuanhao Geng <41546976+GYHHAHA@users.noreply.github.com> Date: Thu, 24 Sep 2020 09:27:27 +0800 Subject: [PATCH 10/12] Change default Offset setting description in DOC --- doc/source/user_guide/timeseries.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/user_guide/timeseries.rst b/doc/source/user_guide/timeseries.rst index 32f0cac3f81e2..d97b1e48bdf07 100644 --- a/doc/source/user_guide/timeseries.rst +++ b/doc/source/user_guide/timeseries.rst @@ -846,7 +846,7 @@ into ``freq`` keyword arguments. The available date offsets and associated frequ :header: "Date Offset", "Frequency String", "Description" :widths: 15, 15, 65 - :class:`~pandas.tseries.offsets.DateOffset`, None, "Generic offset class, defaults to 1 calendar day" + :class:`~pandas.tseries.offsets.DateOffset`, None, "Generic offset class, defaults to absolute 24 hours" :class:`~pandas.tseries.offsets.BDay` or :class:`~pandas.tseries.offsets.BusinessDay`, ``'B'``,"business day (weekday)" :class:`~pandas.tseries.offsets.CDay` or :class:`~pandas.tseries.offsets.CustomBusinessDay`, ``'C'``, "custom business day" :class:`~pandas.tseries.offsets.Week`, ``'W'``, "one week, optionally anchored on a day of the week" From ee41b7b83ae8bdd4c88a3b99f867bed3bed23006 Mon Sep 17 00:00:00 2001 From: Yuanhao Geng <41546976+GYHHAHA@users.noreply.github.com> Date: Sat, 26 Sep 2020 09:17:17 +0800 Subject: [PATCH 11/12] Update timeseries.rst --- doc/source/user_guide/timeseries.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/user_guide/timeseries.rst b/doc/source/user_guide/timeseries.rst index d97b1e48bdf07..4b929fd9219dc 100644 --- a/doc/source/user_guide/timeseries.rst +++ b/doc/source/user_guide/timeseries.rst @@ -846,7 +846,7 @@ into ``freq`` keyword arguments. The available date offsets and associated frequ :header: "Date Offset", "Frequency String", "Description" :widths: 15, 15, 65 - :class:`~pandas.tseries.offsets.DateOffset`, None, "Generic offset class, defaults to absolute 24 hours" + :class:`~pandas.tseries.offsets.DateOffset`, None, "Generic offset class, defaults to 24 absolute hours" :class:`~pandas.tseries.offsets.BDay` or :class:`~pandas.tseries.offsets.BusinessDay`, ``'B'``,"business day (weekday)" :class:`~pandas.tseries.offsets.CDay` or :class:`~pandas.tseries.offsets.CustomBusinessDay`, ``'C'``, "custom business day" :class:`~pandas.tseries.offsets.Week`, ``'W'``, "one week, optionally anchored on a day of the week" From 0defdc68ec4f7816e5602f4deaa2fe17cfbbf192 Mon Sep 17 00:00:00 2001 From: Yuanhao Geng <41546976+GYHHAHA@users.noreply.github.com> Date: Tue, 27 Oct 2020 08:41:32 +0800 Subject: [PATCH 12/12] Update timeseries.rst --- doc/source/user_guide/timeseries.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/user_guide/timeseries.rst b/doc/source/user_guide/timeseries.rst index 4b929fd9219dc..d97b1e48bdf07 100644 --- a/doc/source/user_guide/timeseries.rst +++ b/doc/source/user_guide/timeseries.rst @@ -846,7 +846,7 @@ into ``freq`` keyword arguments. The available date offsets and associated frequ :header: "Date Offset", "Frequency String", "Description" :widths: 15, 15, 65 - :class:`~pandas.tseries.offsets.DateOffset`, None, "Generic offset class, defaults to 24 absolute hours" + :class:`~pandas.tseries.offsets.DateOffset`, None, "Generic offset class, defaults to absolute 24 hours" :class:`~pandas.tseries.offsets.BDay` or :class:`~pandas.tseries.offsets.BusinessDay`, ``'B'``,"business day (weekday)" :class:`~pandas.tseries.offsets.CDay` or :class:`~pandas.tseries.offsets.CustomBusinessDay`, ``'C'``, "custom business day" :class:`~pandas.tseries.offsets.Week`, ``'W'``, "one week, optionally anchored on a day of the week"