From d4428da0556682d01c1be175ef99f237390643d5 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Thu, 18 Feb 2021 18:05:10 +0100 Subject: [PATCH 01/66] Breaking change to offsets.pyx Addresses #8435 --- pandas/_libs/tslibs/offsets.pyx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 2d4704ad3bda6..ad3f83073b91c 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2083,7 +2083,7 @@ cdef class BQuarterEnd(QuarterOffset): """ _output_name = "BusinessQuarterEnd" _default_starting_month = 3 - _from_name_starting_month = 12 + _from_name_starting_month = 3 _prefix = "BQ" _day_opt = "business_end" @@ -2110,7 +2110,7 @@ cdef class BQuarterBegin(QuarterOffset): Timestamp('2020-03-02 05:01:15') """ _output_name = "BusinessQuarterBegin" - _default_starting_month = 3 + _default_starting_month = 1 _from_name_starting_month = 1 _prefix = "BQS" _day_opt = "business_start" @@ -2125,6 +2125,7 @@ cdef class QuarterEnd(QuarterOffset): startingMonth = 3 corresponds to dates like 3/31/2007, 6/30/2007, ... """ _default_starting_month = 3 + _from_name_starting_month = 3 _prefix = "Q" _day_opt = "end" @@ -2146,7 +2147,7 @@ cdef class QuarterBegin(QuarterOffset): startingMonth = 2 corresponds to dates like 2/01/2007, 5/01/2007, ... startingMonth = 3 corresponds to dates like 3/01/2007, 6/01/2007, ... """ - _default_starting_month = 3 + _default_starting_month = 1 _from_name_starting_month = 1 _prefix = "QS" _day_opt = "start" From a546ddc73dbf5f937bfbb1d29d9d347799d84f35 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Sat, 20 Feb 2021 13:22:09 +0100 Subject: [PATCH 02/66] Update offsets.pyx --- pandas/_libs/tslibs/offsets.pyx | 68 ++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index ad3f83073b91c..051b0ec99cc4c 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1986,27 +1986,33 @@ cdef class YearBegin(YearOffset): # Quarter-Based Offset Classes cdef class QuarterOffset(SingleConstructorOffset): - _attributes = tuple(["n", "normalize", "startingMonth"]) + _attributes = tuple(["n", "normalize", "month", "startingMonth"]) # TODO: Consider combining QuarterOffset and YearOffset __init__ at some # point. Also apply_index, is_on_offset, rule_code if # startingMonth vs month attr names are resolved # FIXME: python annotations here breaks things - # _default_starting_month: int - # _from_name_starting_month: int + # _default_month: int + # _from_name_month: int + cdef public: + int _default_month, _from_name_month cdef readonly: - int startingMonth + int month - def __init__(self, n=1, normalize=False, startingMonth=None): + def __init__(self, n=1, normalize=False, month=None, startingMonth=None): BaseOffset.__init__(self, n, normalize) - if startingMonth is None: - startingMonth = self._default_starting_month - self.startingMonth = startingMonth + if month is None: + if startingMonth is None: + self.month = self._default_month + else: + self.month = startingMonth + else: + self.month = month cpdef __setstate__(self, state): - self.startingMonth = state.pop("startingMonth") + self.month = state.pop("month") self.n = state.pop("n") self.normalize = state.pop("normalize") @@ -2014,24 +2020,24 @@ cdef class QuarterOffset(SingleConstructorOffset): def _from_name(cls, suffix=None): kwargs = {} if suffix: - kwargs["startingMonth"] = MONTH_TO_CAL_NUM[suffix] + kwargs["month"] = MONTH_TO_CAL_NUM[suffix] else: - if cls._from_name_starting_month is not None: - kwargs["startingMonth"] = cls._from_name_starting_month + if cls._from_name_month is not None: + kwargs["month"] = cls._from_name_month return cls(**kwargs) @property def rule_code(self) -> str: - month = MONTH_ALIASES[self.startingMonth] + month = MONTH_ALIASES[self.month] return f"{self._prefix}-{month}" def is_anchored(self) -> bool: - return self.n == 1 and self.startingMonth is not None + return self.n == 1 and self.month is not None def is_on_offset(self, dt: datetime) -> bool: if self.normalize and not _is_normalized(dt): return False - mod_month = (dt.month - self.startingMonth) % 3 + mod_month = (dt.month - self.month) % 3 return mod_month == 0 and dt.day == self._get_offset_day(dt) @apply_wraps @@ -2041,9 +2047,9 @@ cdef class QuarterOffset(SingleConstructorOffset): # Then find the month in that quarter containing an is_on_offset date for # self. `months_since` is the number of months to shift other.month # to get to this on-offset month. - months_since = other.month % 3 - self.startingMonth % 3 + months_since = other.month % 3 - self.month % 3 qtrs = roll_qtrday( - other, self.n, self.startingMonth, day_opt=self._day_opt, modby=3 + other, self.n, self.month, day_opt=self._day_opt, modby=3 ) months = qtrs * 3 - months_since return shift_month(other, months, self._day_opt) @@ -2055,7 +2061,7 @@ cdef class QuarterOffset(SingleConstructorOffset): @apply_array_wraps def _apply_array(self, dtarr): shifted = shift_quarters( - dtarr.view("i8"), self.n, self.startingMonth, self._day_opt + dtarr.view("i8"), self.n, self.month, self._day_opt ) return shifted @@ -2070,20 +2076,20 @@ cdef class BQuarterEnd(QuarterOffset): Examples -------- - >>> from pandas.tseries.offset import BQuarterEnd + >>> from pandas.tseries.offsets import BQuarterEnd >>> ts = pd.Timestamp('2020-05-24 05:01:15') >>> ts + BQuarterEnd() Timestamp('2020-06-30 05:01:15') >>> ts + BQuarterEnd(2) Timestamp('2020-09-30 05:01:15') - >>> ts + BQuarterEnd(1, startingMonth=2) + >>> ts + BQuarterEnd(1, month=2) Timestamp('2020-05-29 05:01:15') - >>> ts + BQuarterEnd(startingMonth=2) + >>> ts + BQuarterEnd(month=2) Timestamp('2020-05-29 05:01:15') """ _output_name = "BusinessQuarterEnd" - _default_starting_month = 3 - _from_name_starting_month = 3 + _default_month = 3 + _from_name_month = 3 _prefix = "BQ" _day_opt = "business_end" @@ -2098,20 +2104,20 @@ cdef class BQuarterBegin(QuarterOffset): Examples -------- - >>> from pandas.tseries.offset import BQuarterBegin + >>> from pandas.tseries.offsets import BQuarterBegin >>> ts = pd.Timestamp('2020-05-24 05:01:15') >>> ts + BQuarterBegin() Timestamp('2020-06-01 05:01:15') >>> ts + BQuarterBegin(2) Timestamp('2020-09-01 05:01:15') - >>> ts + BQuarterBegin(startingMonth=2) + >>> ts + BQuarterBegin(month=2) Timestamp('2020-08-03 05:01:15') >>> ts + BQuarterBegin(-1) Timestamp('2020-03-02 05:01:15') """ _output_name = "BusinessQuarterBegin" - _default_starting_month = 1 - _from_name_starting_month = 1 + _default_month = 1 + _from_name_month = 1 _prefix = "BQS" _day_opt = "business_start" @@ -2124,8 +2130,8 @@ cdef class QuarterEnd(QuarterOffset): startingMonth = 2 corresponds to dates like 2/28/2007, 5/31/2007, ... startingMonth = 3 corresponds to dates like 3/31/2007, 6/30/2007, ... """ - _default_starting_month = 3 - _from_name_starting_month = 3 + _default_month = 3 + _from_name_month = 3 _prefix = "Q" _day_opt = "end" @@ -2147,8 +2153,8 @@ cdef class QuarterBegin(QuarterOffset): startingMonth = 2 corresponds to dates like 2/01/2007, 5/01/2007, ... startingMonth = 3 corresponds to dates like 3/01/2007, 6/01/2007, ... """ - _default_starting_month = 1 - _from_name_starting_month = 1 + _default_month = 1 + _from_name_month = 1 _prefix = "QS" _day_opt = "start" From d5647631ee324d02d837bd85f26fc0019318adac Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Sat, 20 Feb 2021 13:49:27 +0100 Subject: [PATCH 03/66] Update offsets.pyx --- pandas/_libs/tslibs/offsets.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 051b0ec99cc4c..e50cc17a32ee5 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1995,10 +1995,10 @@ cdef class QuarterOffset(SingleConstructorOffset): # _default_month: int # _from_name_month: int cdef public: - int _default_month, _from_name_month + int _default_month = 1, _from_name_month = 1 cdef readonly: - int month + int month, startingMonth def __init__(self, n=1, normalize=False, month=None, startingMonth=None): BaseOffset.__init__(self, n, normalize) From 85ee2595a438f942b73280fdf5df931667d73290 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Sat, 20 Feb 2021 13:58:41 +0100 Subject: [PATCH 04/66] Update offsets.pyx --- pandas/_libs/tslibs/offsets.pyx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index e50cc17a32ee5..6ff2dcec195b8 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1994,11 +1994,9 @@ cdef class QuarterOffset(SingleConstructorOffset): # FIXME: python annotations here breaks things # _default_month: int # _from_name_month: int - cdef public: - int _default_month = 1, _from_name_month = 1 cdef readonly: - int month, startingMonth + int month, startingMonth, _default_month, _from_name_month def __init__(self, n=1, normalize=False, month=None, startingMonth=None): BaseOffset.__init__(self, n, normalize) From 8b4ed541910d6faf19ae5f1ccbb0839e0750674e Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Sat, 20 Feb 2021 14:54:40 +0100 Subject: [PATCH 05/66] Update offsets.pyx --- pandas/_libs/tslibs/offsets.pyx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 6ff2dcec195b8..817d6a8a6d495 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2086,8 +2086,8 @@ cdef class BQuarterEnd(QuarterOffset): Timestamp('2020-05-29 05:01:15') """ _output_name = "BusinessQuarterEnd" - _default_month = 3 - _from_name_month = 3 + self._default_month = 3 + self._from_name_month = 3 _prefix = "BQ" _day_opt = "business_end" @@ -2114,8 +2114,8 @@ cdef class BQuarterBegin(QuarterOffset): Timestamp('2020-03-02 05:01:15') """ _output_name = "BusinessQuarterBegin" - _default_month = 1 - _from_name_month = 1 + self._default_month = 1 + self._from_name_month = 1 _prefix = "BQS" _day_opt = "business_start" @@ -2128,8 +2128,8 @@ cdef class QuarterEnd(QuarterOffset): startingMonth = 2 corresponds to dates like 2/28/2007, 5/31/2007, ... startingMonth = 3 corresponds to dates like 3/31/2007, 6/30/2007, ... """ - _default_month = 3 - _from_name_month = 3 + self._default_month = 3 + self._from_name_month = 3 _prefix = "Q" _day_opt = "end" @@ -2151,8 +2151,8 @@ cdef class QuarterBegin(QuarterOffset): startingMonth = 2 corresponds to dates like 2/01/2007, 5/01/2007, ... startingMonth = 3 corresponds to dates like 3/01/2007, 6/01/2007, ... """ - _default_month = 1 - _from_name_month = 1 + self._default_month = 1 + self._from_name_month = 1 _prefix = "QS" _day_opt = "start" From 6e1f3c591ee4f4c0f0df92eda54c9cfa8cccab2d Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Sat, 20 Feb 2021 14:56:27 +0100 Subject: [PATCH 06/66] Update offsets.pyx --- pandas/_libs/tslibs/offsets.pyx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 817d6a8a6d495..5bc14b3c0efeb 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1996,7 +1996,7 @@ cdef class QuarterOffset(SingleConstructorOffset): # _from_name_month: int cdef readonly: - int month, startingMonth, _default_month, _from_name_month + int month, startingMonth def __init__(self, n=1, normalize=False, month=None, startingMonth=None): BaseOffset.__init__(self, n, normalize) @@ -2086,8 +2086,8 @@ cdef class BQuarterEnd(QuarterOffset): Timestamp('2020-05-29 05:01:15') """ _output_name = "BusinessQuarterEnd" - self._default_month = 3 - self._from_name_month = 3 + _default_month = 3 + _from_name_month = 3 _prefix = "BQ" _day_opt = "business_end" @@ -2114,8 +2114,8 @@ cdef class BQuarterBegin(QuarterOffset): Timestamp('2020-03-02 05:01:15') """ _output_name = "BusinessQuarterBegin" - self._default_month = 1 - self._from_name_month = 1 + _default_month = 1 + _from_name_month = 1 _prefix = "BQS" _day_opt = "business_start" @@ -2128,8 +2128,8 @@ cdef class QuarterEnd(QuarterOffset): startingMonth = 2 corresponds to dates like 2/28/2007, 5/31/2007, ... startingMonth = 3 corresponds to dates like 3/31/2007, 6/30/2007, ... """ - self._default_month = 3 - self._from_name_month = 3 + _default_month = 3 + _from_name_month = 3 _prefix = "Q" _day_opt = "end" @@ -2151,8 +2151,8 @@ cdef class QuarterBegin(QuarterOffset): startingMonth = 2 corresponds to dates like 2/01/2007, 5/01/2007, ... startingMonth = 3 corresponds to dates like 3/01/2007, 6/01/2007, ... """ - self._default_month = 1 - self._from_name_month = 1 + _default_month = 1 + _from_name_month = 1 _prefix = "QS" _day_opt = "start" From 01ce09ffca3236e11e1a4b8497c5f1e08629e8de Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Sat, 20 Feb 2021 15:26:49 +0100 Subject: [PATCH 07/66] Update offsets.pyx --- pandas/_libs/tslibs/offsets.pyx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 5bc14b3c0efeb..26fc1c6b30abe 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2136,11 +2136,11 @@ cdef class QuarterEnd(QuarterOffset): cdef readonly: int _period_dtype_code - def __init__(self, n=1, normalize=False, startingMonth=None): + def __init__(self, n=1, normalize=False, month=None, startingMonth=None): # Because QuarterEnd can be the freq for a Period, define its # _period_dtype_code at construction for performance - QuarterOffset.__init__(self, n, normalize, startingMonth) - self._period_dtype_code = PeriodDtypeCode.Q_DEC + self.startingMonth % 12 + QuarterOffset.__init__(self, n, normalize, month, startingMonth) + self._period_dtype_code = PeriodDtypeCode.Q_DEC + self.month % 12 cdef class QuarterBegin(QuarterOffset): From b95cc702837e34a1eb45dbfdc4dc1c330809931e Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Sat, 20 Feb 2021 16:37:17 +0100 Subject: [PATCH 08/66] Update test_constructors.py --- pandas/tests/indexes/datetimes/test_constructors.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/indexes/datetimes/test_constructors.py b/pandas/tests/indexes/datetimes/test_constructors.py index 07cd89c23f1e0..778dd217b238e 100644 --- a/pandas/tests/indexes/datetimes/test_constructors.py +++ b/pandas/tests/indexes/datetimes/test_constructors.py @@ -1046,14 +1046,14 @@ def test_datetimeindex_constructor_misc(self): idx1 = date_range(start=sdate, end=edate, freq="QS") idx2 = date_range( - start=sdate, end=edate, freq=offsets.QuarterBegin(startingMonth=1) + start=sdate, end=edate, freq=offsets.QuarterBegin(month=1) ) assert len(idx1) == len(idx2) assert idx1.freq == idx2.freq idx1 = date_range(start=sdate, end=edate, freq="BQ") idx2 = date_range( - start=sdate, end=edate, freq=offsets.BQuarterEnd(startingMonth=12) + start=sdate, end=edate, freq=offsets.BQuarterEnd(month=3) ) assert len(idx1) == len(idx2) assert idx1.freq == idx2.freq From ccb9b9791d6176643bbcd2ef76ffe790cd6e0323 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Sat, 20 Feb 2021 16:42:04 +0100 Subject: [PATCH 09/66] Update test_misc.py --- pandas/tests/indexes/datetimes/test_misc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/indexes/datetimes/test_misc.py b/pandas/tests/indexes/datetimes/test_misc.py index d230aa43e43d1..ceabd984798f5 100644 --- a/pandas/tests/indexes/datetimes/test_misc.py +++ b/pandas/tests/indexes/datetimes/test_misc.py @@ -234,7 +234,7 @@ def test_datetimeindex_accessors(self): exp = DatetimeIndex([], freq="D", tz=dti.tz, name="name") tm.assert_index_equal(res, exp) - dti = date_range(freq="BQ-FEB", start=datetime(1998, 1, 1), periods=4) + dti = date_range(freq="BQ-MAR", start=datetime(1998, 1, 1), periods=4) assert sum(dti.is_quarter_start) == 0 assert sum(dti.is_quarter_end) == 4 From f1204def15a2fbd221e74c341d519f4ad8109744 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Sat, 20 Feb 2021 16:47:12 +0100 Subject: [PATCH 10/66] Update test_period_index.py --- pandas/tests/resample/test_period_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/resample/test_period_index.py b/pandas/tests/resample/test_period_index.py index 5dab0cbafbc59..483c3bca57256 100644 --- a/pandas/tests/resample/test_period_index.py +++ b/pandas/tests/resample/test_period_index.py @@ -130,7 +130,7 @@ def test_basic_downsample(self, simple_period_range_series): "rule,expected_error_msg", [ ("a-dec", ""), - ("q-mar", ""), + ("q-mar", ""), ("M", ""), ("w-thu", ""), ], From a8c8a3d8dfe1d785064748f983b02c898e410e63 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Sat, 20 Feb 2021 16:48:18 +0100 Subject: [PATCH 11/66] Update offsets.pyx --- pandas/_libs/tslibs/offsets.pyx | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 26fc1c6b30abe..ca8fefbafac2e 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2068,9 +2068,9 @@ cdef class BQuarterEnd(QuarterOffset): """ DateOffset increments between the last business day of each Quarter. - startingMonth = 1 corresponds to dates like 1/31/2007, 4/30/2007, ... - startingMonth = 2 corresponds to dates like 2/28/2007, 5/31/2007, ... - startingMonth = 3 corresponds to dates like 3/30/2007, 6/29/2007, ... + month = 1 corresponds to dates like 1/31/2007, 4/30/2007, ... + month = 2 corresponds to dates like 2/28/2007, 5/31/2007, ... + month = 3 corresponds to dates like 3/30/2007, 6/29/2007, ... Examples -------- @@ -2096,9 +2096,9 @@ cdef class BQuarterBegin(QuarterOffset): """ DateOffset increments between the first business day of each Quarter. - startingMonth = 1 corresponds to dates like 1/01/2007, 4/01/2007, ... - startingMonth = 2 corresponds to dates like 2/01/2007, 5/01/2007, ... - startingMonth = 3 corresponds to dates like 3/01/2007, 6/01/2007, ... + month = 1 corresponds to dates like 1/01/2007, 4/01/2007, ... + month = 2 corresponds to dates like 2/01/2007, 5/01/2007, ... + month = 3 corresponds to dates like 3/01/2007, 6/01/2007, ... Examples -------- @@ -2124,9 +2124,9 @@ cdef class QuarterEnd(QuarterOffset): """ DateOffset increments between Quarter end dates. - startingMonth = 1 corresponds to dates like 1/31/2007, 4/30/2007, ... - startingMonth = 2 corresponds to dates like 2/28/2007, 5/31/2007, ... - startingMonth = 3 corresponds to dates like 3/31/2007, 6/30/2007, ... + month = 1 corresponds to dates like 1/31/2007, 4/30/2007, ... + month = 2 corresponds to dates like 2/28/2007, 5/31/2007, ... + month = 3 corresponds to dates like 3/31/2007, 6/30/2007, ... """ _default_month = 3 _from_name_month = 3 @@ -2147,9 +2147,9 @@ cdef class QuarterBegin(QuarterOffset): """ DateOffset increments between Quarter start dates. - startingMonth = 1 corresponds to dates like 1/01/2007, 4/01/2007, ... - startingMonth = 2 corresponds to dates like 2/01/2007, 5/01/2007, ... - startingMonth = 3 corresponds to dates like 3/01/2007, 6/01/2007, ... + month = 1 corresponds to dates like 1/01/2007, 4/01/2007, ... + month = 2 corresponds to dates like 2/01/2007, 5/01/2007, ... + month = 3 corresponds to dates like 3/01/2007, 6/01/2007, ... """ _default_month = 1 _from_name_month = 1 From 1338c1ff811b4b71f38a6670a31574dd3725fa5a Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Sat, 20 Feb 2021 16:58:29 +0100 Subject: [PATCH 12/66] Update test_dst.py --- pandas/tests/tseries/offsets/test_dst.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/tseries/offsets/test_dst.py b/pandas/tests/tseries/offsets/test_dst.py index 0ae94b6b57640..cc9064fc8e62d 100644 --- a/pandas/tests/tseries/offsets/test_dst.py +++ b/pandas/tests/tseries/offsets/test_dst.py @@ -159,7 +159,7 @@ def test_springforward_singular(self): YearEnd: ["11/2/2012", "12/31/2012"], BYearBegin: ["11/2/2012", "1/1/2013"], BYearEnd: ["11/2/2012", "12/31/2012"], - QuarterBegin: ["11/2/2012", "12/1/2012"], + QuarterBegin: ["11/2/2012", "1/1/2013"], QuarterEnd: ["11/2/2012", "12/31/2012"], BQuarterBegin: ["11/2/2012", "12/3/2012"], BQuarterEnd: ["11/2/2012", "12/31/2012"], From d7c8cada71980da8c53ee1c722bd59afaa9c0043 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Sat, 20 Feb 2021 17:10:39 +0100 Subject: [PATCH 13/66] Update test_dst.py --- pandas/tests/tseries/offsets/test_dst.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/tseries/offsets/test_dst.py b/pandas/tests/tseries/offsets/test_dst.py index cc9064fc8e62d..2039987e835b4 100644 --- a/pandas/tests/tseries/offsets/test_dst.py +++ b/pandas/tests/tseries/offsets/test_dst.py @@ -161,7 +161,7 @@ def test_springforward_singular(self): BYearEnd: ["11/2/2012", "12/31/2012"], QuarterBegin: ["11/2/2012", "1/1/2013"], QuarterEnd: ["11/2/2012", "12/31/2012"], - BQuarterBegin: ["11/2/2012", "12/3/2012"], + BQuarterBegin: ["11/2/2021", "1/3/2022"], BQuarterEnd: ["11/2/2012", "12/31/2012"], Day: ["11/4/2012", "11/4/2012 23:00"], }.items() From 3399d67c6a33e8511e787d56c40b18fc4619f712 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Sat, 20 Feb 2021 17:16:58 +0100 Subject: [PATCH 14/66] Update test_offsets.py --- pandas/tests/tseries/offsets/test_offsets.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index 50bfc21637407..08326c436c3e3 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -84,8 +84,8 @@ class TestCommon(Base): "BYearBegin": Timestamp("2011-01-03 09:00:00"), "YearEnd": Timestamp("2011-12-31 09:00:00"), "BYearEnd": Timestamp("2011-12-30 09:00:00"), - "QuarterBegin": Timestamp("2011-03-01 09:00:00"), - "BQuarterBegin": Timestamp("2011-03-01 09:00:00"), + "QuarterBegin": Timestamp("2011-04-01 09:00:00"), + "BQuarterBegin": Timestamp("2011-01-03 09:00:00"), "QuarterEnd": Timestamp("2011-03-31 09:00:00"), "BQuarterEnd": Timestamp("2011-03-31 09:00:00"), "BusinessHour": Timestamp("2011-01-03 10:00:00"), From 79fe74756169338c1817e88c792f4ebef2322266 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Sat, 20 Feb 2021 17:24:28 +0100 Subject: [PATCH 15/66] Update test_offsets.py --- pandas/tests/tseries/offsets/test_offsets.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index 08326c436c3e3..ee3ef17093eee 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -320,8 +320,8 @@ def test_rollback(self, offset_types): "BYearBegin": Timestamp("2010-01-01 09:00:00"), "YearEnd": Timestamp("2010-12-31 09:00:00"), "BYearEnd": Timestamp("2010-12-31 09:00:00"), - "QuarterBegin": Timestamp("2010-12-01 09:00:00"), - "BQuarterBegin": Timestamp("2010-12-01 09:00:00"), + "QuarterBegin": Timestamp("2010-10-01 09:00:00"), + "BQuarterBegin": Timestamp("2010-10-01 09:00:00"), "QuarterEnd": Timestamp("2010-12-31 09:00:00"), "BQuarterEnd": Timestamp("2010-12-31 09:00:00"), "BusinessHour": Timestamp("2010-12-31 17:00:00"), From 2f456cb8f05d60314bce800488a399fdcb5f8d8e Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Sat, 20 Feb 2021 17:37:34 +0100 Subject: [PATCH 16/66] Update test_constructors.py --- pandas/tests/indexes/datetimes/test_constructors.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pandas/tests/indexes/datetimes/test_constructors.py b/pandas/tests/indexes/datetimes/test_constructors.py index 778dd217b238e..ae8296be90af1 100644 --- a/pandas/tests/indexes/datetimes/test_constructors.py +++ b/pandas/tests/indexes/datetimes/test_constructors.py @@ -1045,16 +1045,12 @@ def test_datetimeindex_constructor_misc(self): assert idx1.freq == idx2.freq idx1 = date_range(start=sdate, end=edate, freq="QS") - idx2 = date_range( - start=sdate, end=edate, freq=offsets.QuarterBegin(month=1) - ) + idx2 = date_range(start=sdate, end=edate, freq=offsets.QuarterBegin(month=1)) assert len(idx1) == len(idx2) assert idx1.freq == idx2.freq idx1 = date_range(start=sdate, end=edate, freq="BQ") - idx2 = date_range( - start=sdate, end=edate, freq=offsets.BQuarterEnd(month=3) - ) + idx2 = date_range(start=sdate, end=edate, freq=offsets.BQuarterEnd(month=3)) assert len(idx1) == len(idx2) assert idx1.freq == idx2.freq From 3fd9a64edcd8ae8acee3d416cbd5b67e78847441 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Sat, 20 Feb 2021 18:53:58 +0100 Subject: [PATCH 17/66] Update test_misc.py --- pandas/tests/indexes/datetimes/test_misc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/indexes/datetimes/test_misc.py b/pandas/tests/indexes/datetimes/test_misc.py index ceabd984798f5..07ae486fcb965 100644 --- a/pandas/tests/indexes/datetimes/test_misc.py +++ b/pandas/tests/indexes/datetimes/test_misc.py @@ -234,7 +234,7 @@ def test_datetimeindex_accessors(self): exp = DatetimeIndex([], freq="D", tz=dti.tz, name="name") tm.assert_index_equal(res, exp) - dti = date_range(freq="BQ-MAR", start=datetime(1998, 1, 1), periods=4) + dti = date_range(freq="BQ-DEC", start=datetime(1998, 1, 1), periods=4) assert sum(dti.is_quarter_start) == 0 assert sum(dti.is_quarter_end) == 4 From 3ce1de99e5f81999264f1d9299fa7f3d7dc49152 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Sat, 20 Feb 2021 19:06:57 +0100 Subject: [PATCH 18/66] Update test_offsets.py --- pandas/tests/tseries/offsets/test_offsets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index ee3ef17093eee..51b5eeba6abd5 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -320,7 +320,7 @@ def test_rollback(self, offset_types): "BYearBegin": Timestamp("2010-01-01 09:00:00"), "YearEnd": Timestamp("2010-12-31 09:00:00"), "BYearEnd": Timestamp("2010-12-31 09:00:00"), - "QuarterBegin": Timestamp("2010-10-01 09:00:00"), + "QuarterBegin": Timestamp("2011-01-01 09:00:00"), "BQuarterBegin": Timestamp("2010-10-01 09:00:00"), "QuarterEnd": Timestamp("2010-12-31 09:00:00"), "BQuarterEnd": Timestamp("2010-12-31 09:00:00"), From 7e1e5d2235435f954538e268f4e9ad0c4b722d54 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Sat, 20 Feb 2021 19:21:28 +0100 Subject: [PATCH 19/66] Update test_yqm_offsets.py --- .../tests/tseries/offsets/test_yqm_offsets.py | 210 +++++++++--------- 1 file changed, 105 insertions(+), 105 deletions(-) diff --git a/pandas/tests/tseries/offsets/test_yqm_offsets.py b/pandas/tests/tseries/offsets/test_yqm_offsets.py index 260f7368123a4..b3c45bae2e39a 100644 --- a/pandas/tests/tseries/offsets/test_yqm_offsets.py +++ b/pandas/tests/tseries/offsets/test_yqm_offsets.py @@ -436,27 +436,27 @@ def test_is_on_offset(self, case): class TestQuarterBegin(Base): def test_repr(self): - expected = "" + expected = "" assert repr(QuarterBegin()) == expected - expected = "" - assert repr(QuarterBegin(startingMonth=3)) == expected - expected = "" - assert repr(QuarterBegin(startingMonth=1)) == expected + expected = "" + assert repr(QuarterBegin(month=3)) == expected + expected = "" + assert repr(QuarterBegin(month=1)) == expected def test_is_anchored(self): - assert QuarterBegin(startingMonth=1).is_anchored() + assert QuarterBegin(month=1).is_anchored() assert QuarterBegin().is_anchored() - assert not QuarterBegin(2, startingMonth=1).is_anchored() + assert not QuarterBegin(2, month=1).is_anchored() def test_offset_corner_case(self): # corner - offset = QuarterBegin(n=-1, startingMonth=1) + offset = QuarterBegin(n=-1, month=1) assert datetime(2010, 2, 1) + offset == datetime(2010, 1, 1) offset_cases = [] offset_cases.append( ( - QuarterBegin(startingMonth=1), + QuarterBegin(month=1), { datetime(2007, 12, 1): datetime(2008, 1, 1), datetime(2008, 1, 1): datetime(2008, 4, 1), @@ -472,7 +472,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - QuarterBegin(startingMonth=2), + QuarterBegin(month=2), { datetime(2008, 1, 1): datetime(2008, 2, 1), datetime(2008, 1, 31): datetime(2008, 2, 1), @@ -488,7 +488,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - QuarterBegin(startingMonth=1, n=0), + QuarterBegin(month=1, n=0), { datetime(2008, 1, 1): datetime(2008, 1, 1), datetime(2008, 12, 1): datetime(2009, 1, 1), @@ -505,7 +505,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - QuarterBegin(startingMonth=1, n=-1), + QuarterBegin(month=1, n=-1), { datetime(2008, 1, 1): datetime(2007, 10, 1), datetime(2008, 1, 31): datetime(2008, 1, 1), @@ -522,7 +522,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - QuarterBegin(startingMonth=1, n=2), + QuarterBegin(month=1, n=2), { datetime(2008, 1, 1): datetime(2008, 7, 1), datetime(2008, 2, 15): datetime(2008, 7, 1), @@ -546,27 +546,27 @@ class TestQuarterEnd(Base): _offset = QuarterEnd def test_repr(self): - expected = "" + expected = "" assert repr(QuarterEnd()) == expected - expected = "" - assert repr(QuarterEnd(startingMonth=3)) == expected - expected = "" - assert repr(QuarterEnd(startingMonth=1)) == expected + expected = "" + assert repr(QuarterEnd(month=3)) == expected + expected = "" + assert repr(QuarterEnd(month=1)) == expected def test_is_anchored(self): - assert QuarterEnd(startingMonth=1).is_anchored() + assert QuarterEnd(month=1).is_anchored() assert QuarterEnd().is_anchored() - assert not QuarterEnd(2, startingMonth=1).is_anchored() + assert not QuarterEnd(2, month=1).is_anchored() def test_offset_corner_case(self): # corner - offset = QuarterEnd(n=-1, startingMonth=1) + offset = QuarterEnd(n=-1, month=1) assert datetime(2010, 2, 1) + offset == datetime(2010, 1, 31) offset_cases = [] offset_cases.append( ( - QuarterEnd(startingMonth=1), + QuarterEnd(month=1), { datetime(2008, 1, 1): datetime(2008, 1, 31), datetime(2008, 1, 31): datetime(2008, 4, 30), @@ -582,7 +582,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - QuarterEnd(startingMonth=2), + QuarterEnd(month=2), { datetime(2008, 1, 1): datetime(2008, 2, 29), datetime(2008, 1, 31): datetime(2008, 2, 29), @@ -598,7 +598,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - QuarterEnd(startingMonth=1, n=0), + QuarterEnd(month=1, n=0), { datetime(2008, 1, 1): datetime(2008, 1, 31), datetime(2008, 1, 31): datetime(2008, 1, 31), @@ -614,7 +614,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - QuarterEnd(startingMonth=1, n=-1), + QuarterEnd(month=1, n=-1), { datetime(2008, 1, 1): datetime(2007, 10, 31), datetime(2008, 1, 31): datetime(2007, 10, 31), @@ -631,7 +631,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - QuarterEnd(startingMonth=1, n=2), + QuarterEnd(month=1, n=2), { datetime(2008, 1, 31): datetime(2008, 7, 31), datetime(2008, 2, 15): datetime(2008, 7, 31), @@ -651,36 +651,36 @@ def test_offset(self, case): assert_offset_equal(offset, base, expected) on_offset_cases = [ - (QuarterEnd(1, startingMonth=1), datetime(2008, 1, 31), True), - (QuarterEnd(1, startingMonth=1), datetime(2007, 12, 31), False), - (QuarterEnd(1, startingMonth=1), datetime(2008, 2, 29), False), - (QuarterEnd(1, startingMonth=1), datetime(2007, 3, 30), False), - (QuarterEnd(1, startingMonth=1), datetime(2007, 3, 31), False), - (QuarterEnd(1, startingMonth=1), datetime(2008, 4, 30), True), - (QuarterEnd(1, startingMonth=1), datetime(2008, 5, 30), False), - (QuarterEnd(1, startingMonth=1), datetime(2008, 5, 31), False), - (QuarterEnd(1, startingMonth=1), datetime(2007, 6, 29), False), - (QuarterEnd(1, startingMonth=1), datetime(2007, 6, 30), False), - (QuarterEnd(1, startingMonth=2), datetime(2008, 1, 31), False), - (QuarterEnd(1, startingMonth=2), datetime(2007, 12, 31), False), - (QuarterEnd(1, startingMonth=2), datetime(2008, 2, 29), True), - (QuarterEnd(1, startingMonth=2), datetime(2007, 3, 30), False), - (QuarterEnd(1, startingMonth=2), datetime(2007, 3, 31), False), - (QuarterEnd(1, startingMonth=2), datetime(2008, 4, 30), False), - (QuarterEnd(1, startingMonth=2), datetime(2008, 5, 30), False), - (QuarterEnd(1, startingMonth=2), datetime(2008, 5, 31), True), - (QuarterEnd(1, startingMonth=2), datetime(2007, 6, 29), False), - (QuarterEnd(1, startingMonth=2), datetime(2007, 6, 30), False), - (QuarterEnd(1, startingMonth=3), datetime(2008, 1, 31), False), - (QuarterEnd(1, startingMonth=3), datetime(2007, 12, 31), True), - (QuarterEnd(1, startingMonth=3), datetime(2008, 2, 29), False), - (QuarterEnd(1, startingMonth=3), datetime(2007, 3, 30), False), - (QuarterEnd(1, startingMonth=3), datetime(2007, 3, 31), True), - (QuarterEnd(1, startingMonth=3), datetime(2008, 4, 30), False), - (QuarterEnd(1, startingMonth=3), datetime(2008, 5, 30), False), - (QuarterEnd(1, startingMonth=3), datetime(2008, 5, 31), False), - (QuarterEnd(1, startingMonth=3), datetime(2007, 6, 29), False), - (QuarterEnd(1, startingMonth=3), datetime(2007, 6, 30), True), + (QuarterEnd(1, month=1), datetime(2008, 1, 31), True), + (QuarterEnd(1, month=1), datetime(2007, 12, 31), False), + (QuarterEnd(1, month=1), datetime(2008, 2, 29), False), + (QuarterEnd(1, month=1), datetime(2007, 3, 30), False), + (QuarterEnd(1, month=1), datetime(2007, 3, 31), False), + (QuarterEnd(1, month=1), datetime(2008, 4, 30), True), + (QuarterEnd(1, month=1), datetime(2008, 5, 30), False), + (QuarterEnd(1, month=1), datetime(2008, 5, 31), False), + (QuarterEnd(1, month=1), datetime(2007, 6, 29), False), + (QuarterEnd(1, month=1), datetime(2007, 6, 30), False), + (QuarterEnd(1, month=2), datetime(2008, 1, 31), False), + (QuarterEnd(1, month=2), datetime(2007, 12, 31), False), + (QuarterEnd(1, month=2), datetime(2008, 2, 29), True), + (QuarterEnd(1, month=2), datetime(2007, 3, 30), False), + (QuarterEnd(1, month=2), datetime(2007, 3, 31), False), + (QuarterEnd(1, month=2), datetime(2008, 4, 30), False), + (QuarterEnd(1, month=2), datetime(2008, 5, 30), False), + (QuarterEnd(1, month=2), datetime(2008, 5, 31), True), + (QuarterEnd(1, month=2), datetime(2007, 6, 29), False), + (QuarterEnd(1, month=2), datetime(2007, 6, 30), False), + (QuarterEnd(1, month=3), datetime(2008, 1, 31), False), + (QuarterEnd(1, month=3), datetime(2007, 12, 31), True), + (QuarterEnd(1, month=3), datetime(2008, 2, 29), False), + (QuarterEnd(1, month=3), datetime(2007, 3, 30), False), + (QuarterEnd(1, month=3), datetime(2007, 3, 31), True), + (QuarterEnd(1, month=3), datetime(2008, 4, 30), False), + (QuarterEnd(1, month=3), datetime(2008, 5, 30), False), + (QuarterEnd(1, month=3), datetime(2008, 5, 31), False), + (QuarterEnd(1, month=3), datetime(2007, 6, 29), False), + (QuarterEnd(1, month=3), datetime(2007, 6, 30), True), ] @pytest.mark.parametrize("case", on_offset_cases) @@ -693,27 +693,27 @@ class TestBQuarterBegin(Base): _offset = BQuarterBegin def test_repr(self): - expected = "" + expected = "" assert repr(BQuarterBegin()) == expected - expected = "" + expected = "" assert repr(BQuarterBegin(startingMonth=3)) == expected - expected = "" + expected = "" assert repr(BQuarterBegin(startingMonth=1)) == expected def test_is_anchored(self): - assert BQuarterBegin(startingMonth=1).is_anchored() + assert BQuarterBegin(month=1).is_anchored() assert BQuarterBegin().is_anchored() - assert not BQuarterBegin(2, startingMonth=1).is_anchored() + assert not BQuarterBegin(2, month=1).is_anchored() def test_offset_corner_case(self): # corner - offset = BQuarterBegin(n=-1, startingMonth=1) + offset = BQuarterBegin(n=-1, month=1) assert datetime(2007, 4, 3) + offset == datetime(2007, 4, 2) offset_cases = [] offset_cases.append( ( - BQuarterBegin(startingMonth=1), + BQuarterBegin(month=1), { datetime(2008, 1, 1): datetime(2008, 4, 1), datetime(2008, 1, 31): datetime(2008, 4, 1), @@ -736,7 +736,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - BQuarterBegin(startingMonth=2), + BQuarterBegin(month=2), { datetime(2008, 1, 1): datetime(2008, 2, 1), datetime(2008, 1, 31): datetime(2008, 2, 1), @@ -755,7 +755,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - BQuarterBegin(startingMonth=1, n=0), + BQuarterBegin(month=1, n=0), { datetime(2008, 1, 1): datetime(2008, 1, 1), datetime(2007, 12, 31): datetime(2008, 1, 1), @@ -775,7 +775,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - BQuarterBegin(startingMonth=1, n=-1), + BQuarterBegin(month=1, n=-1), { datetime(2008, 1, 1): datetime(2007, 10, 1), datetime(2008, 1, 31): datetime(2008, 1, 1), @@ -794,7 +794,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - BQuarterBegin(startingMonth=1, n=2), + BQuarterBegin(month=1, n=2), { datetime(2008, 1, 1): datetime(2008, 7, 1), datetime(2008, 1, 15): datetime(2008, 7, 1), @@ -818,27 +818,27 @@ class TestBQuarterEnd(Base): _offset = BQuarterEnd def test_repr(self): - expected = "" + expected = "" assert repr(BQuarterEnd()) == expected - expected = "" + expected = "" assert repr(BQuarterEnd(startingMonth=3)) == expected - expected = "" + expected = "" assert repr(BQuarterEnd(startingMonth=1)) == expected def test_is_anchored(self): - assert BQuarterEnd(startingMonth=1).is_anchored() + assert BQuarterEnd(month=1).is_anchored() assert BQuarterEnd().is_anchored() - assert not BQuarterEnd(2, startingMonth=1).is_anchored() + assert not BQuarterEnd(2, month=1).is_anchored() def test_offset_corner_case(self): # corner - offset = BQuarterEnd(n=-1, startingMonth=1) + offset = BQuarterEnd(n=-1, month=1) assert datetime(2010, 1, 31) + offset == datetime(2010, 1, 29) offset_cases = [] offset_cases.append( ( - BQuarterEnd(startingMonth=1), + BQuarterEnd(month=1), { datetime(2008, 1, 1): datetime(2008, 1, 31), datetime(2008, 1, 31): datetime(2008, 4, 30), @@ -854,7 +854,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - BQuarterEnd(startingMonth=2), + BQuarterEnd(month=2), { datetime(2008, 1, 1): datetime(2008, 2, 29), datetime(2008, 1, 31): datetime(2008, 2, 29), @@ -870,7 +870,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - BQuarterEnd(startingMonth=1, n=0), + BQuarterEnd(month=1, n=0), { datetime(2008, 1, 1): datetime(2008, 1, 31), datetime(2008, 1, 31): datetime(2008, 1, 31), @@ -886,7 +886,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - BQuarterEnd(startingMonth=1, n=-1), + BQuarterEnd(month=1, n=-1), { datetime(2008, 1, 1): datetime(2007, 10, 31), datetime(2008, 1, 31): datetime(2007, 10, 31), @@ -902,7 +902,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - BQuarterEnd(startingMonth=1, n=2), + BQuarterEnd(month=1, n=2), { datetime(2008, 1, 31): datetime(2008, 7, 31), datetime(2008, 2, 15): datetime(2008, 7, 31), @@ -922,33 +922,33 @@ def test_offset(self, case): assert_offset_equal(offset, base, expected) on_offset_cases = [ - (BQuarterEnd(1, startingMonth=1), datetime(2008, 1, 31), True), - (BQuarterEnd(1, startingMonth=1), datetime(2007, 12, 31), False), - (BQuarterEnd(1, startingMonth=1), datetime(2008, 2, 29), False), - (BQuarterEnd(1, startingMonth=1), datetime(2007, 3, 30), False), - (BQuarterEnd(1, startingMonth=1), datetime(2007, 3, 31), False), - (BQuarterEnd(1, startingMonth=1), datetime(2008, 4, 30), True), - (BQuarterEnd(1, startingMonth=1), datetime(2008, 5, 30), False), - (BQuarterEnd(1, startingMonth=1), datetime(2007, 6, 29), False), - (BQuarterEnd(1, startingMonth=1), datetime(2007, 6, 30), False), - (BQuarterEnd(1, startingMonth=2), datetime(2008, 1, 31), False), - (BQuarterEnd(1, startingMonth=2), datetime(2007, 12, 31), False), - (BQuarterEnd(1, startingMonth=2), datetime(2008, 2, 29), True), - (BQuarterEnd(1, startingMonth=2), datetime(2007, 3, 30), False), - (BQuarterEnd(1, startingMonth=2), datetime(2007, 3, 31), False), - (BQuarterEnd(1, startingMonth=2), datetime(2008, 4, 30), False), - (BQuarterEnd(1, startingMonth=2), datetime(2008, 5, 30), True), - (BQuarterEnd(1, startingMonth=2), datetime(2007, 6, 29), False), - (BQuarterEnd(1, startingMonth=2), datetime(2007, 6, 30), False), - (BQuarterEnd(1, startingMonth=3), datetime(2008, 1, 31), False), - (BQuarterEnd(1, startingMonth=3), datetime(2007, 12, 31), True), - (BQuarterEnd(1, startingMonth=3), datetime(2008, 2, 29), False), - (BQuarterEnd(1, startingMonth=3), datetime(2007, 3, 30), True), - (BQuarterEnd(1, startingMonth=3), datetime(2007, 3, 31), False), - (BQuarterEnd(1, startingMonth=3), datetime(2008, 4, 30), False), - (BQuarterEnd(1, startingMonth=3), datetime(2008, 5, 30), False), - (BQuarterEnd(1, startingMonth=3), datetime(2007, 6, 29), True), - (BQuarterEnd(1, startingMonth=3), datetime(2007, 6, 30), False), + (BQuarterEnd(1, month=1), datetime(2008, 1, 31), True), + (BQuarterEnd(1, month=1), datetime(2007, 12, 31), False), + (BQuarterEnd(1, month=1), datetime(2008, 2, 29), False), + (BQuarterEnd(1, month=1), datetime(2007, 3, 30), False), + (BQuarterEnd(1, month=1), datetime(2007, 3, 31), False), + (BQuarterEnd(1, month=1), datetime(2008, 4, 30), True), + (BQuarterEnd(1, month=1), datetime(2008, 5, 30), False), + (BQuarterEnd(1, month=1), datetime(2007, 6, 29), False), + (BQuarterEnd(1, month=1), datetime(2007, 6, 30), False), + (BQuarterEnd(1, month=2), datetime(2008, 1, 31), False), + (BQuarterEnd(1, month=2), datetime(2007, 12, 31), False), + (BQuarterEnd(1, month=2), datetime(2008, 2, 29), True), + (BQuarterEnd(1, month=2), datetime(2007, 3, 30), False), + (BQuarterEnd(1, month=2), datetime(2007, 3, 31), False), + (BQuarterEnd(1, month=2), datetime(2008, 4, 30), False), + (BQuarterEnd(1, month=2), datetime(2008, 5, 30), True), + (BQuarterEnd(1, month=2), datetime(2007, 6, 29), False), + (BQuarterEnd(1, month=2), datetime(2007, 6, 30), False), + (BQuarterEnd(1, month=3), datetime(2008, 1, 31), False), + (BQuarterEnd(1, month=3), datetime(2007, 12, 31), True), + (BQuarterEnd(1, month=3), datetime(2008, 2, 29), False), + (BQuarterEnd(1, month=3), datetime(2007, 3, 30), True), + (BQuarterEnd(1, month=3), datetime(2007, 3, 31), False), + (BQuarterEnd(1, month=3), datetime(2008, 4, 30), False), + (BQuarterEnd(1, month=3), datetime(2008, 5, 30), False), + (BQuarterEnd(1, month=3), datetime(2007, 6, 29), True), + (BQuarterEnd(1, month=3), datetime(2007, 6, 30), False), ] @pytest.mark.parametrize("case", on_offset_cases) From f9e7c3b3033367d728047e95e8af8438ddd19e84 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Sat, 20 Feb 2021 21:49:13 +0100 Subject: [PATCH 20/66] Update test_period_index.py --- pandas/tests/resample/test_period_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/resample/test_period_index.py b/pandas/tests/resample/test_period_index.py index 483c3bca57256..d02454b3636ef 100644 --- a/pandas/tests/resample/test_period_index.py +++ b/pandas/tests/resample/test_period_index.py @@ -130,7 +130,7 @@ def test_basic_downsample(self, simple_period_range_series): "rule,expected_error_msg", [ ("a-dec", ""), - ("q-mar", ""), + ("q-mar", ""), ("M", ""), ("w-thu", ""), ], From 27a24ba65d08ea4711a34ee28b79f8d05c2c2ee2 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Sat, 20 Feb 2021 21:53:39 +0100 Subject: [PATCH 21/66] Update test_offsets.py --- pandas/tests/tseries/offsets/test_offsets.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index 51b5eeba6abd5..ee9738d1b859b 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -84,7 +84,7 @@ class TestCommon(Base): "BYearBegin": Timestamp("2011-01-03 09:00:00"), "YearEnd": Timestamp("2011-12-31 09:00:00"), "BYearEnd": Timestamp("2011-12-30 09:00:00"), - "QuarterBegin": Timestamp("2011-04-01 09:00:00"), + "QuarterBegin": Timestamp("2011-01-01 09:00:00"), "BQuarterBegin": Timestamp("2011-01-03 09:00:00"), "QuarterEnd": Timestamp("2011-03-31 09:00:00"), "BQuarterEnd": Timestamp("2011-03-31 09:00:00"), @@ -320,7 +320,7 @@ def test_rollback(self, offset_types): "BYearBegin": Timestamp("2010-01-01 09:00:00"), "YearEnd": Timestamp("2010-12-31 09:00:00"), "BYearEnd": Timestamp("2010-12-31 09:00:00"), - "QuarterBegin": Timestamp("2011-01-01 09:00:00"), + "QuarterBegin": Timestamp("2010-10-01 09:00:00"), "BQuarterBegin": Timestamp("2010-10-01 09:00:00"), "QuarterEnd": Timestamp("2010-12-31 09:00:00"), "BQuarterEnd": Timestamp("2010-12-31 09:00:00"), From 197fa1b24886269bbe2c879979cc8e72b36f3928 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Sat, 20 Feb 2021 23:05:21 +0100 Subject: [PATCH 22/66] Update test_offsets.py --- pandas/tests/tseries/offsets/test_offsets.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index ee9738d1b859b..51b5eeba6abd5 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -84,7 +84,7 @@ class TestCommon(Base): "BYearBegin": Timestamp("2011-01-03 09:00:00"), "YearEnd": Timestamp("2011-12-31 09:00:00"), "BYearEnd": Timestamp("2011-12-30 09:00:00"), - "QuarterBegin": Timestamp("2011-01-01 09:00:00"), + "QuarterBegin": Timestamp("2011-04-01 09:00:00"), "BQuarterBegin": Timestamp("2011-01-03 09:00:00"), "QuarterEnd": Timestamp("2011-03-31 09:00:00"), "BQuarterEnd": Timestamp("2011-03-31 09:00:00"), @@ -320,7 +320,7 @@ def test_rollback(self, offset_types): "BYearBegin": Timestamp("2010-01-01 09:00:00"), "YearEnd": Timestamp("2010-12-31 09:00:00"), "BYearEnd": Timestamp("2010-12-31 09:00:00"), - "QuarterBegin": Timestamp("2010-10-01 09:00:00"), + "QuarterBegin": Timestamp("2011-01-01 09:00:00"), "BQuarterBegin": Timestamp("2010-10-01 09:00:00"), "QuarterEnd": Timestamp("2010-12-31 09:00:00"), "BQuarterEnd": Timestamp("2010-12-31 09:00:00"), From 8154be9dd68135885fd0e985d9d04e29f6519b8b Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Thu, 18 Mar 2021 00:31:19 +0100 Subject: [PATCH 23/66] Rename startingMonth to month Rename `startingMonth` to `month` for `BQuarterEnd`, `BQuarterBegin`, `QuarterEnd`, `QuarterBegin`. --- pandas/_libs/tslibs/offsets.pyx | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index ca8fefbafac2e..72fe481cca0cb 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1986,26 +1986,20 @@ cdef class YearBegin(YearOffset): # Quarter-Based Offset Classes cdef class QuarterOffset(SingleConstructorOffset): - _attributes = tuple(["n", "normalize", "month", "startingMonth"]) + _attributes = tuple(["n", "normalize", "month"]) # TODO: Consider combining QuarterOffset and YearOffset __init__ at some - # point. Also apply_index, is_on_offset, rule_code if - # startingMonth vs month attr names are resolved + # point. Also apply_index, is_on_offset, rule_code. # FIXME: python annotations here breaks things - # _default_month: int - # _from_name_month: int cdef readonly: - int month, startingMonth + int month - def __init__(self, n=1, normalize=False, month=None, startingMonth=None): + def __init__(self, n=1, normalize=False, month=None): BaseOffset.__init__(self, n, normalize) if month is None: - if startingMonth is None: - self.month = self._default_month - else: - self.month = startingMonth + self.month = self._default_month else: self.month = month @@ -2136,10 +2130,10 @@ cdef class QuarterEnd(QuarterOffset): cdef readonly: int _period_dtype_code - def __init__(self, n=1, normalize=False, month=None, startingMonth=None): + def __init__(self, n=1, normalize=False, month=None): # Because QuarterEnd can be the freq for a Period, define its # _period_dtype_code at construction for performance - QuarterOffset.__init__(self, n, normalize, month, startingMonth) + QuarterOffset.__init__(self, n, normalize, month) self._period_dtype_code = PeriodDtypeCode.Q_DEC + self.month % 12 From 2757983798e64cddeac1e0487afb612ecf8ed752 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Thu, 18 Mar 2021 00:53:50 +0100 Subject: [PATCH 24/66] Update test_to_offset.py Rename startingMonth to month. --- pandas/tests/tslibs/test_to_offset.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/tests/tslibs/test_to_offset.py b/pandas/tests/tslibs/test_to_offset.py index 27ddbb82f49a9..ec3b20a152f69 100644 --- a/pandas/tests/tslibs/test_to_offset.py +++ b/pandas/tests/tslibs/test_to_offset.py @@ -158,9 +158,9 @@ def test_to_offset_pd_timedelta(kwargs, expected): [ ("W", offsets.Week(weekday=6)), ("W-SUN", offsets.Week(weekday=6)), - ("Q", offsets.QuarterEnd(startingMonth=12)), - ("Q-DEC", offsets.QuarterEnd(startingMonth=12)), - ("Q-MAY", offsets.QuarterEnd(startingMonth=5)), + ("Q", offsets.QuarterEnd(month=12)), + ("Q-DEC", offsets.QuarterEnd(month=12)), + ("Q-MAY", offsets.QuarterEnd(month=5)), ("SM", offsets.SemiMonthEnd(day_of_month=15)), ("SM-15", offsets.SemiMonthEnd(day_of_month=15)), ("SM-1", offsets.SemiMonthEnd(day_of_month=1)), From dc55ee688e6fe44d0d3eb1eaf0ba24dc3bc42666 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Thu, 18 Mar 2021 00:54:28 +0100 Subject: [PATCH 25/66] Update test_libfrequencies.py Rename startingMonth to month. --- pandas/tests/tslibs/test_libfrequencies.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/tslibs/test_libfrequencies.py b/pandas/tests/tslibs/test_libfrequencies.py index 83f28f6b5dc01..0640d4da78772 100644 --- a/pandas/tests/tslibs/test_libfrequencies.py +++ b/pandas/tests/tslibs/test_libfrequencies.py @@ -13,9 +13,9 @@ ("D", "DEC"), (offsets.Day().freqstr, "DEC"), ("Q", "DEC"), - (offsets.QuarterEnd(startingMonth=12).freqstr, "DEC"), + (offsets.QuarterEnd(month=12).freqstr, "DEC"), ("Q-JAN", "JAN"), - (offsets.QuarterEnd(startingMonth=1).freqstr, "JAN"), + (offsets.QuarterEnd(month=1).freqstr, "JAN"), ("A-DEC", "DEC"), ("Y-DEC", "DEC"), (offsets.YearEnd().freqstr, "DEC"), From 12cf5bf5a9a7a2d31635ef00195ad08979d521ba Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Thu, 18 Mar 2021 01:35:35 +0100 Subject: [PATCH 26/66] Update test_period.py Rename startingMonth to month --- pandas/tests/arithmetic/test_period.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/tests/arithmetic/test_period.py b/pandas/tests/arithmetic/test_period.py index bb78e29924ba2..58108c93afc6a 100644 --- a/pandas/tests/arithmetic/test_period.py +++ b/pandas/tests/arithmetic/test_period.py @@ -665,7 +665,7 @@ def test_sub_n_gt_1_ticks(self, tick_classes, n): "offset, kwd_name", [ (pd.offsets.YearEnd, "month"), - (pd.offsets.QuarterEnd, "startingMonth"), + (pd.offsets.QuarterEnd, "month"), (pd.offsets.MonthEnd, None), (pd.offsets.Week, "weekday"), ], @@ -839,8 +839,8 @@ def test_pi_add_offset_array(self, box): pi = PeriodIndex([Period("2015Q1"), Period("2016Q2")]) offs = box( [ - pd.offsets.QuarterEnd(n=1, startingMonth=12), - pd.offsets.QuarterEnd(n=-2, startingMonth=12), + pd.offsets.QuarterEnd(n=1, month=12), + pd.offsets.QuarterEnd(n=-2, month=12), ] ) expected = PeriodIndex([Period("2015Q2"), Period("2015Q4")]) @@ -870,8 +870,8 @@ def test_pi_sub_offset_array(self, box): pi = PeriodIndex([Period("2015Q1"), Period("2016Q2")]) other = box( [ - pd.offsets.QuarterEnd(n=1, startingMonth=12), - pd.offsets.QuarterEnd(n=-2, startingMonth=12), + pd.offsets.QuarterEnd(n=1, month=12), + pd.offsets.QuarterEnd(n=-2, month=12), ] ) From 8b91c5c6fe2f3be3215aa6e6df19e9b6b96ee1ff Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Thu, 18 Mar 2021 09:47:05 +0100 Subject: [PATCH 27/66] Update offsets.pyx Pickling error investigation. --- pandas/_libs/tslibs/offsets.pyx | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 9381698b92d67..89186d7f3cd44 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2007,6 +2007,7 @@ cdef class QuarterOffset(SingleConstructorOffset): self.month = state.pop("month") self.n = state.pop("n") self.normalize = state.pop("normalize") + self._cache = {} @classmethod def _from_name(cls, suffix=None): From 9b4f609e499e6def97c75398a172a63f247abb7e Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Thu, 18 Mar 2021 09:49:22 +0100 Subject: [PATCH 28/66] Remove startingMonth reference Remove startingMonth reference from test_basic_downsample() in test_period_index.py --- pandas/tests/resample/test_period_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/resample/test_period_index.py b/pandas/tests/resample/test_period_index.py index 4dee91cd3a20f..401a912ec0799 100644 --- a/pandas/tests/resample/test_period_index.py +++ b/pandas/tests/resample/test_period_index.py @@ -130,7 +130,7 @@ def test_basic_downsample(self, simple_period_range_series): "rule,expected_error_msg", [ ("a-dec", ""), - ("q-mar", ""), + ("q-mar", ""), ("M", ""), ("w-thu", ""), ], From d1099a85211de0ac1c5cdd56feebb6963f48701e Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Thu, 18 Mar 2021 09:52:29 +0100 Subject: [PATCH 29/66] Rename startingMonth to month Rename startingMonth to month in test_period.py --- pandas/tests/scalar/period/test_period.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/tests/scalar/period/test_period.py b/pandas/tests/scalar/period/test_period.py index 7dcd4dc979eb2..c5b34ce0bcd74 100644 --- a/pandas/tests/scalar/period/test_period.py +++ b/pandas/tests/scalar/period/test_period.py @@ -198,10 +198,10 @@ def test_period_constructor_offsets(self): assert Period("3/10/12", freq=offsets.Day()) == Period("3/10/12", freq="D") assert Period( - year=2005, quarter=1, freq=offsets.QuarterEnd(startingMonth=12) + year=2005, quarter=1, freq=offsets.QuarterEnd(month=12) ) == Period(year=2005, quarter=1, freq="Q") assert Period( - year=2005, quarter=2, freq=offsets.QuarterEnd(startingMonth=12) + year=2005, quarter=2, freq=offsets.QuarterEnd(month=12) ) == Period(year=2005, quarter=2, freq="Q") assert Period(year=2005, month=3, day=1, freq=offsets.Day()) == Period( @@ -1252,7 +1252,7 @@ def test_sub_n_gt_1_ticks(self, tick_classes, n): "offset, kwd_name", [ (offsets.YearEnd, "month"), - (offsets.QuarterEnd, "startingMonth"), + (offsets.QuarterEnd, "month"), (offsets.MonthEnd, None), (offsets.Week, "weekday"), ], From 8892734bbe9744a944e4417c3aeefcfa0483af87 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Thu, 18 Mar 2021 15:40:56 +0100 Subject: [PATCH 30/66] Update offset_frequency.rst Rename startingMonth to month. --- doc/source/reference/offset_frequency.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/source/reference/offset_frequency.rst b/doc/source/reference/offset_frequency.rst index e6271a7806706..c5ed8d718bfb7 100644 --- a/doc/source/reference/offset_frequency.rst +++ b/doc/source/reference/offset_frequency.rst @@ -655,7 +655,7 @@ Properties BQuarterEnd.normalize BQuarterEnd.rule_code BQuarterEnd.n - BQuarterEnd.startingMonth + BQuarterEnd.month Methods ~~~~~~~ @@ -690,7 +690,7 @@ Properties BQuarterBegin.normalize BQuarterBegin.rule_code BQuarterBegin.n - BQuarterBegin.startingMonth + BQuarterBegin.month Methods ~~~~~~~ @@ -725,7 +725,7 @@ Properties QuarterEnd.normalize QuarterEnd.rule_code QuarterEnd.n - QuarterEnd.startingMonth + QuarterEnd.month Methods ~~~~~~~ @@ -760,7 +760,7 @@ Properties QuarterBegin.normalize QuarterBegin.rule_code QuarterBegin.n - QuarterBegin.startingMonth + QuarterBegin.month Methods ~~~~~~~ From 1cde76e71f86acf53ff3c91d3fa7b80613fc8ff6 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Thu, 18 Mar 2021 19:01:12 +0100 Subject: [PATCH 31/66] DOC: Rename startingMonth to month --- doc/source/whatsnew/v0.18.0.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/source/whatsnew/v0.18.0.rst b/doc/source/whatsnew/v0.18.0.rst index 829c04dac9f2d..8c63faa825fa7 100644 --- a/doc/source/whatsnew/v0.18.0.rst +++ b/doc/source/whatsnew/v0.18.0.rst @@ -689,8 +689,8 @@ forward to the next anchor point. d = pd.Timestamp('2014-02-01') d - d + pd.offsets.QuarterBegin(n=0, startingMonth=2) - d + pd.offsets.QuarterBegin(n=0, startingMonth=1) + d + pd.offsets.QuarterBegin(n=0, month=2) + d + pd.offsets.QuarterBegin(n=0, month=1) For the ``QuarterBegin`` offset in previous versions, the date would be rolled *backwards* if date was in the same month as the quarter start date. @@ -699,7 +699,7 @@ For the ``QuarterBegin`` offset in previous versions, the date would be rolled In [3]: d = pd.Timestamp('2014-02-15') - In [4]: d + pd.offsets.QuarterBegin(n=0, startingMonth=2) + In [4]: d + pd.offsets.QuarterBegin(n=0, month=2) Out[4]: Timestamp('2014-02-01 00:00:00') This behavior has been corrected in version 0.18.0, which is consistent with @@ -708,7 +708,7 @@ other anchored offsets like ``MonthBegin`` and ``YearBegin``. .. ipython:: python d = pd.Timestamp('2014-02-15') - d + pd.offsets.QuarterBegin(n=0, startingMonth=2) + d + pd.offsets.QuarterBegin(n=0, month=2) .. _whatsnew_0180.breaking.resample: From 4e659a51ac1eeb280e62f1544344277c2ee7a346 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Thu, 18 Mar 2021 19:07:32 +0100 Subject: [PATCH 32/66] Rename startingMonth to month --- .../tests/tseries/offsets/test_yqm_offsets.py | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/pandas/tests/tseries/offsets/test_yqm_offsets.py b/pandas/tests/tseries/offsets/test_yqm_offsets.py index b3c45bae2e39a..6f601318b5a3d 100644 --- a/pandas/tests/tseries/offsets/test_yqm_offsets.py +++ b/pandas/tests/tseries/offsets/test_yqm_offsets.py @@ -436,11 +436,11 @@ def test_is_on_offset(self, case): class TestQuarterBegin(Base): def test_repr(self): - expected = "" + expected = "" assert repr(QuarterBegin()) == expected - expected = "" + expected = "" assert repr(QuarterBegin(month=3)) == expected - expected = "" + expected = "" assert repr(QuarterBegin(month=1)) == expected def test_is_anchored(self): @@ -546,11 +546,11 @@ class TestQuarterEnd(Base): _offset = QuarterEnd def test_repr(self): - expected = "" + expected = "" assert repr(QuarterEnd()) == expected - expected = "" + expected = "" assert repr(QuarterEnd(month=3)) == expected - expected = "" + expected = "" assert repr(QuarterEnd(month=1)) == expected def test_is_anchored(self): @@ -693,12 +693,12 @@ class TestBQuarterBegin(Base): _offset = BQuarterBegin def test_repr(self): - expected = "" + expected = "" assert repr(BQuarterBegin()) == expected - expected = "" - assert repr(BQuarterBegin(startingMonth=3)) == expected - expected = "" - assert repr(BQuarterBegin(startingMonth=1)) == expected + expected = "" + assert repr(BQuarterBegin(month=3)) == expected + expected = "" + assert repr(BQuarterBegin(month=1)) == expected def test_is_anchored(self): assert BQuarterBegin(month=1).is_anchored() @@ -818,12 +818,12 @@ class TestBQuarterEnd(Base): _offset = BQuarterEnd def test_repr(self): - expected = "" + expected = "" assert repr(BQuarterEnd()) == expected - expected = "" - assert repr(BQuarterEnd(startingMonth=3)) == expected - expected = "" - assert repr(BQuarterEnd(startingMonth=1)) == expected + expected = "" + assert repr(BQuarterEnd(month=3)) == expected + expected = "" + assert repr(BQuarterEnd(month=1)) == expected def test_is_anchored(self): assert BQuarterEnd(month=1).is_anchored() From 36df0f7f54fde370b041ab933b3c5594453bd9fc Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Thu, 18 Mar 2021 19:24:15 +0100 Subject: [PATCH 33/66] Fix "QuarterBegin" timestamp in test_rollback --- pandas/tests/tseries/offsets/test_offsets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index 054618998e595..a9d51f281ec1c 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -320,7 +320,7 @@ def test_rollback(self, offset_types): "BYearBegin": Timestamp("2010-01-01 09:00:00"), "YearEnd": Timestamp("2010-12-31 09:00:00"), "BYearEnd": Timestamp("2010-12-31 09:00:00"), - "QuarterBegin": Timestamp("2011-01-01 09:00:00"), + "QuarterBegin": Timestamp("2010-10-01 09:00:00"), "BQuarterBegin": Timestamp("2010-10-01 09:00:00"), "QuarterEnd": Timestamp("2010-12-31 09:00:00"), "BQuarterEnd": Timestamp("2010-12-31 09:00:00"), From 1ec3a9b4b6d09c3e469bba41cde7375be29a9af0 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Thu, 18 Mar 2021 21:11:06 +0100 Subject: [PATCH 34/66] Fix timestamp for QuarterBegin --- pandas/tests/tseries/offsets/test_offsets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index a9d51f281ec1c..13d580958d847 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -84,7 +84,7 @@ class TestCommon(Base): "BYearBegin": Timestamp("2011-01-03 09:00:00"), "YearEnd": Timestamp("2011-12-31 09:00:00"), "BYearEnd": Timestamp("2011-12-30 09:00:00"), - "QuarterBegin": Timestamp("2011-04-01 09:00:00"), + "QuarterBegin": Timestamp("2011-01-01 09:00:00"), "BQuarterBegin": Timestamp("2011-01-03 09:00:00"), "QuarterEnd": Timestamp("2011-03-31 09:00:00"), "BQuarterEnd": Timestamp("2011-03-31 09:00:00"), From 1a6bf2c986015a527d73ca0b54767a62b034af9c Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Fri, 19 Mar 2021 12:07:41 +0100 Subject: [PATCH 35/66] Fix offsets tests for QuarterBegin --- pandas/tests/tseries/offsets/test_offsets.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index 13d580958d847..028119abf7a9a 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -84,7 +84,7 @@ class TestCommon(Base): "BYearBegin": Timestamp("2011-01-03 09:00:00"), "YearEnd": Timestamp("2011-12-31 09:00:00"), "BYearEnd": Timestamp("2011-12-30 09:00:00"), - "QuarterBegin": Timestamp("2011-01-01 09:00:00"), + "QuarterBegin": Timestamp("2011-04-01 09:00:00"), "BQuarterBegin": Timestamp("2011-01-03 09:00:00"), "QuarterEnd": Timestamp("2011-03-31 09:00:00"), "BQuarterEnd": Timestamp("2011-03-31 09:00:00"), @@ -260,6 +260,7 @@ def test_rollforward(self, offset_types): "Day", "MonthBegin", "SemiMonthBegin", + "QuarterBegin", "YearBegin", "Week", "Hour", @@ -286,6 +287,7 @@ def test_rollforward(self, offset_types): "DateOffset": Timestamp("2011-01-02 00:00:00"), "MonthBegin": Timestamp("2011-02-01 00:00:00"), "SemiMonthBegin": Timestamp("2011-01-15 00:00:00"), + "QuarterBegin": Timestamp("2011-04-01 00:00:00"), "YearBegin": Timestamp("2012-01-01 00:00:00"), "Week": Timestamp("2011-01-08 00:00:00"), "Hour": Timestamp("2011-01-01 00:00:00"), @@ -320,7 +322,6 @@ def test_rollback(self, offset_types): "BYearBegin": Timestamp("2010-01-01 09:00:00"), "YearEnd": Timestamp("2010-12-31 09:00:00"), "BYearEnd": Timestamp("2010-12-31 09:00:00"), - "QuarterBegin": Timestamp("2010-10-01 09:00:00"), "BQuarterBegin": Timestamp("2010-10-01 09:00:00"), "QuarterEnd": Timestamp("2010-12-31 09:00:00"), "BQuarterEnd": Timestamp("2010-12-31 09:00:00"), @@ -338,6 +339,7 @@ def test_rollback(self, offset_types): "Day", "MonthBegin", "SemiMonthBegin", + "QuarterBegin", "YearBegin", "Week", "Hour", @@ -360,6 +362,7 @@ def test_rollback(self, offset_types): "DateOffset": Timestamp("2010-12-31 00:00:00"), "MonthBegin": Timestamp("2010-12-01 00:00:00"), "SemiMonthBegin": Timestamp("2010-12-15 00:00:00"), + "QuarterBegin": Timestamp("2010-10-01 00:00:00"), "YearBegin": Timestamp("2010-01-01 00:00:00"), "Week": Timestamp("2010-12-25 00:00:00"), "Hour": Timestamp("2011-01-01 00:00:00"), From a8e47a4110d8b57aa1fcee5a9164f70fa6f409ed Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Fri, 19 Mar 2021 14:21:49 +0100 Subject: [PATCH 36/66] Rename startingMonth to month --- pandas/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 688ad6dcc5e48..03514627ff162 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -162,7 +162,7 @@ def pytest_runtest_setup(item): cls, n=st.integers(-24, 24), normalize=st.booleans(), - startingMonth=st.integers(min_value=1, max_value=12), + month=st.integers(min_value=1, max_value=12), ), ) From cbce0bdda093c84a8fa6c5628cce9f2c8be527d1 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Fri, 19 Mar 2021 14:40:54 +0100 Subject: [PATCH 37/66] Fix pickling of quarter-based offsets --- pandas/_libs/tslibs/offsets.pyx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 89186d7f3cd44..c7f17714f2c58 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1840,7 +1840,7 @@ cdef class YearOffset(SingleConstructorOffset): """ _attributes = tuple(["n", "normalize", "month"]) - # _default_month: int # FIXME: python annotation here breaks things + # FIXME: python annotation here breaks things cdef readonly: int month @@ -1998,10 +1998,11 @@ cdef class QuarterOffset(SingleConstructorOffset): def __init__(self, n=1, normalize=False, month=None): BaseOffset.__init__(self, n, normalize) - if month is None: - self.month = self._default_month - else: - self.month = month + month = month if month is not None else self._default_month + self.month = month + + if month < 1 or month > 12: + raise ValueError("Month must go from 1 to 12") cpdef __setstate__(self, state): self.month = state.pop("month") From 9506ee03624f615a5bcaef975f1da24748bacb9b Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Fri, 19 Mar 2021 20:33:33 +0100 Subject: [PATCH 38/66] Fix pickling of quarter-based offsets --- pandas/_libs/tslibs/offsets.pyx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index c7f17714f2c58..4661c906a7fe9 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1990,7 +1990,7 @@ cdef class QuarterOffset(SingleConstructorOffset): # TODO: Consider combining QuarterOffset and YearOffset __init__ at some # point. Also apply_index, is_on_offset, rule_code. - # FIXME: python annotations here breaks things + # FIXME: python annotation here breaks things cdef readonly: int month @@ -2005,7 +2005,10 @@ cdef class QuarterOffset(SingleConstructorOffset): raise ValueError("Month must go from 1 to 12") cpdef __setstate__(self, state): - self.month = state.pop("month") + try: + self.month = state.pop("month") + except: + self.month = state.pop("startingMonth") # for legacy pickles self.n = state.pop("n") self.normalize = state.pop("normalize") self._cache = {} From 6a7b0db1848a251ef20749a38c1da7e7c88e526c Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Fri, 19 Mar 2021 23:01:32 +0100 Subject: [PATCH 39/66] Deprecate startingMonth --- pandas/_libs/tslibs/offsets.pyx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 4661c906a7fe9..70c85ac0b8dba 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1994,21 +1994,34 @@ cdef class QuarterOffset(SingleConstructorOffset): cdef readonly: int month + int startingMonth # Backwards compatibility - def __init__(self, n=1, normalize=False, month=None): + def __init__(self, n=1, normalize=False, month=None, + *, startingMonth=None): # Backwards compatibility BaseOffset.__init__(self, n, normalize) + # Backwards compatibility + if month and startingMonth and month != startingMonth: + raise TypeError("Offset received both month and startingMonth") + elif month is None and startingMonth is not None: + warnings.warn( + "startingMonth is deprecated, use month instead.", + DeprecationWarning, + stacklevel=2 + ) + month = startingMonth + month = month if month is not None else self._default_month self.month = month if month < 1 or month > 12: - raise ValueError("Month must go from 1 to 12") + raise ValueError("Month must go from 1 to 12.") cpdef __setstate__(self, state): try: self.month = state.pop("month") except: - self.month = state.pop("startingMonth") # for legacy pickles + self.month = state.pop("startingMonth") # For legacy pickles self.n = state.pop("n") self.normalize = state.pop("normalize") self._cache = {} From e5ad2ace5c53d51d96041818037226205d08348b Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Tue, 30 Mar 2021 18:48:57 +0200 Subject: [PATCH 40/66] Add deprecation warning test --- pandas/tests/tseries/offsets/test_offsets.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index 028119abf7a9a..3a90289fa313f 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -873,3 +873,7 @@ def test_dateoffset_immutable(attribute): msg = "DateOffset objects are immutable" with pytest.raises(AttributeError, match=msg): setattr(offset, attribute, 5) + + +with tm.assert_produces_warning(DeprecationWarning): + offsets.QuarterEnd(startingMonth=1) From 66d37b540876d22d08ef16f33b143ea0ddbb9113 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Tue, 30 Mar 2021 19:22:54 +0200 Subject: [PATCH 41/66] Add test_startingMonth_deprecation_warning --- pandas/tests/tseries/offsets/test_offsets.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index 3a90289fa313f..27ad85def504c 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -875,5 +875,15 @@ def test_dateoffset_immutable(attribute): setattr(offset, attribute, 5) -with tm.assert_produces_warning(DeprecationWarning): - offsets.QuarterEnd(startingMonth=1) +@pytest.mark.parametrize( + "offset_type", + [ + "QuarterBegin", + "QuarterEnd", + "BQuarterBegin", + "BQuarterEnd", + ], +) +def test_startingMonth_deprecation_warning(offset_type): + with tm.assert_produces_warning(DeprecationWarning): + eval(f"offsets.{offset_type}(startingMonth=1)") From 57fe35049f0662a52050daa600ad3e70d0bc8847 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Tue, 30 Mar 2021 20:46:45 +0200 Subject: [PATCH 42/66] Add startingMonth deprecation to QuarterEnd --- 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 70c85ac0b8dba..287050ed67791 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2148,7 +2148,8 @@ cdef class QuarterEnd(QuarterOffset): cdef readonly: int _period_dtype_code - def __init__(self, n=1, normalize=False, month=None): + def __init__(self, n=1, normalize=False, month=None, + *, startingMonth=None): # Backwards compatibility # Because QuarterEnd can be the freq for a Period, define its # _period_dtype_code at construction for performance QuarterOffset.__init__(self, n, normalize, month) From e2665e08517044296c59c5252e03a4686a0248a7 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Tue, 30 Mar 2021 20:49:20 +0200 Subject: [PATCH 43/66] Fix linting --- pandas/tests/tseries/offsets/test_offsets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index 27ad85def504c..79250c7790390 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -873,7 +873,7 @@ def test_dateoffset_immutable(attribute): msg = "DateOffset objects are immutable" with pytest.raises(AttributeError, match=msg): setattr(offset, attribute, 5) - + @pytest.mark.parametrize( "offset_type", From 94947d4d61713bef23069850ea5ea32f8c27c530 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Tue, 30 Mar 2021 21:25:06 +0200 Subject: [PATCH 44/66] Add startingMonth deprecation to QuarterEnd --- 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 287050ed67791..6002565b91124 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2152,7 +2152,8 @@ cdef class QuarterEnd(QuarterOffset): *, startingMonth=None): # Backwards compatibility # Because QuarterEnd can be the freq for a Period, define its # _period_dtype_code at construction for performance - QuarterOffset.__init__(self, n, normalize, month) + QuarterOffset.__init__(self, n, normalize, month, + *, startingMonth) self._period_dtype_code = PeriodDtypeCode.Q_DEC + self.month % 12 From 30ad2fff208d72ffaecf66b3605149b5852b3da6 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Tue, 30 Mar 2021 21:35:06 +0200 Subject: [PATCH 45/66] startingMonth depreciation fix --- 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 6002565b91124..fca57aca0e665 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2153,7 +2153,7 @@ cdef class QuarterEnd(QuarterOffset): # Because QuarterEnd can be the freq for a Period, define its # _period_dtype_code at construction for performance QuarterOffset.__init__(self, n, normalize, month, - *, startingMonth) + *, startingMonth) self._period_dtype_code = PeriodDtypeCode.Q_DEC + self.month % 12 From 9621c16a38bc9f757b504fb1c68397fe32c04eaf Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Tue, 30 Mar 2021 22:23:41 +0200 Subject: [PATCH 46/66] 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 fca57aca0e665..e0af7f0b1dc70 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2153,7 +2153,7 @@ cdef class QuarterEnd(QuarterOffset): # Because QuarterEnd can be the freq for a Period, define its # _period_dtype_code at construction for performance QuarterOffset.__init__(self, n, normalize, month, - *, startingMonth) + *, startingMonth=startingMonth) self._period_dtype_code = PeriodDtypeCode.Q_DEC + self.month % 12 From b9d638351964058746231c23f45158cfea93f1b0 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Wed, 31 Mar 2021 09:29:19 +0200 Subject: [PATCH 47/66] 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 e0af7f0b1dc70..e3d1da5bbb83e 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2153,7 +2153,7 @@ cdef class QuarterEnd(QuarterOffset): # Because QuarterEnd can be the freq for a Period, define its # _period_dtype_code at construction for performance QuarterOffset.__init__(self, n, normalize, month, - *, startingMonth=startingMonth) + startingMonth=startingMonth) self._period_dtype_code = PeriodDtypeCode.Q_DEC + self.month % 12 From 5b893432b0a84a3301a0433d8182b37a0d0d1723 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Wed, 31 Mar 2021 10:40:24 +0200 Subject: [PATCH 48/66] Create QuarterBase docstring --- pandas/_libs/tslibs/offsets.pyx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index e3d1da5bbb83e..93bd0302f142e 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1986,6 +1986,26 @@ cdef class YearBegin(YearOffset): # Quarter-Based Offset Classes cdef class QuarterOffset(SingleConstructorOffset): + """ + Base for quarter-based offset classes. + + Parameters + ---------- + n : int, default 1 + Number of quarters to offset. + normalize : bool, default False + If true, the time component of the resulting date-time is converted to + 00:00:00, i.e. midnight (the start, not the end of date-time). + month : int + The calendar month number (1 for January) of the beginning or ending + month in a custom-defined quarter to be used as offset. + startingMonth : int + The calendar month number (1 for January) of the beginning or ending + month in a custom-defined quarter to be used as offset. + + .. deprecated:: 1.X.X + """ + _attributes = tuple(["n", "normalize", "month"]) # TODO: Consider combining QuarterOffset and YearOffset __init__ at some # point. Also apply_index, is_on_offset, rule_code. From 62082879c52bb27799e1ea1b76c32c86ea444b63 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Wed, 31 Mar 2021 11:37:25 +0200 Subject: [PATCH 49/66] Update docstrings for quarter-based offsets --- pandas/_libs/tslibs/offsets.pyx | 74 ++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 5 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 93bd0302f142e..8d2af137701a8 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1994,14 +1994,14 @@ cdef class QuarterOffset(SingleConstructorOffset): n : int, default 1 Number of quarters to offset. normalize : bool, default False - If true, the time component of the resulting date-time is converted to - 00:00:00, i.e. midnight (the start, not the end of date-time). + If true, the time component of the resulting date-time is converted + to 00:00:00, i.e. midnight (the start, not the end of date-time). month : int The calendar month number (1 for January) of the beginning or ending - month in a custom-defined quarter to be used as offset. + month in a custom-defined quarter to be used as an offset. startingMonth : int The calendar month number (1 for January) of the beginning or ending - month in a custom-defined quarter to be used as offset. + month in a custom-defined quarter to be used as an offset. .. deprecated:: 1.X.X """ @@ -2098,12 +2098,28 @@ cdef class QuarterOffset(SingleConstructorOffset): cdef class BQuarterEnd(QuarterOffset): """ - DateOffset increments between the last business day of each Quarter. + DateOffset increments between the last business day of each quarter. month = 1 corresponds to dates like 1/31/2007, 4/30/2007, ... month = 2 corresponds to dates like 2/28/2007, 5/31/2007, ... month = 3 corresponds to dates like 3/30/2007, 6/29/2007, ... + Parameters + ---------- + n : int, default 1 + Number of business quarters to offset. + normalize : bool, default False + If true, the time component of the resulting date-time is converted + to 00:00:00, i.e. midnight (the start, not the end of date-time). + month : int, default 3 + The calendar month number (3 for March) of the last month + in a custom-defined business quarter to be used as an offset. + startingMonth : int, default 3 + The calendar month number (3 for March) of the last month + in a custom-defined business quarter to be used as an offset. + + .. deprecated:: 1.X.X + Examples -------- >>> from pandas.tseries.offsets import BQuarterEnd @@ -2132,6 +2148,22 @@ cdef class BQuarterBegin(QuarterOffset): month = 2 corresponds to dates like 2/01/2007, 5/01/2007, ... month = 3 corresponds to dates like 3/01/2007, 6/01/2007, ... + Parameters + ---------- + n : int, default 1 + Number of business quarters to offset. + normalize : bool, default False + If true, the time component of the resulting date-time is converted + to 00:00:00, i.e. midnight (the start, not the end of date-time). + month : int, default 1 + The calendar month number (1 for January) of the first month + in a custom-defined business quarter to be used as an offset. + startingMonth : int, default 1 + The calendar month number (1 for January) of the first month + in a custom-defined business quarter to be used as an offset. + + .. deprecated:: 1.X.X + Examples -------- >>> from pandas.tseries.offsets import BQuarterBegin @@ -2159,6 +2191,22 @@ cdef class QuarterEnd(QuarterOffset): month = 1 corresponds to dates like 1/31/2007, 4/30/2007, ... month = 2 corresponds to dates like 2/28/2007, 5/31/2007, ... month = 3 corresponds to dates like 3/31/2007, 6/30/2007, ... + + Parameters + ---------- + n : int, default 1 + Number of quarters to offset. + normalize : bool, default False + If true, the time component of the resulting date-time is converted + to 00:00:00, i.e. midnight (the start, not the end of date-time). + month : int, default 3 + The calendar month number (3 for March) of the last month + in a custom-defined quarter to be used as an offset. + startingMonth : int, default 3 + The calendar month number (3 for March) of the last month + in a custom-defined quarter to be used as an offset. + + .. deprecated:: 1.X.X """ _default_month = 3 _from_name_month = 3 @@ -2184,6 +2232,22 @@ cdef class QuarterBegin(QuarterOffset): month = 1 corresponds to dates like 1/01/2007, 4/01/2007, ... month = 2 corresponds to dates like 2/01/2007, 5/01/2007, ... month = 3 corresponds to dates like 3/01/2007, 6/01/2007, ... + + Parameters + ---------- + n : int, default 1 + Number of quarters to offset. + normalize : bool, default False + If true, the time component of the resulting date-time is converted + to 00:00:00, i.e. midnight (the start, not the end of date-time). + month : int, default 1 + The calendar month number (1 for January) of the first month + in a custom-defined quarter to be used as an offset. + startingMonth : int, default 1 + The calendar month number (1 for January) of the first month + in a custom-defined quarter to be used as an offset. + + .. deprecated:: 1.X.X """ _default_month = 1 _from_name_month = 1 From ace4503e426a455946d0e3e6286afcfc73564942 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Wed, 31 Mar 2021 13:57:07 +0200 Subject: [PATCH 50/66] Update v0.18.0.rst --- doc/source/whatsnew/v0.18.0.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/source/whatsnew/v0.18.0.rst b/doc/source/whatsnew/v0.18.0.rst index 8c63faa825fa7..829c04dac9f2d 100644 --- a/doc/source/whatsnew/v0.18.0.rst +++ b/doc/source/whatsnew/v0.18.0.rst @@ -689,8 +689,8 @@ forward to the next anchor point. d = pd.Timestamp('2014-02-01') d - d + pd.offsets.QuarterBegin(n=0, month=2) - d + pd.offsets.QuarterBegin(n=0, month=1) + d + pd.offsets.QuarterBegin(n=0, startingMonth=2) + d + pd.offsets.QuarterBegin(n=0, startingMonth=1) For the ``QuarterBegin`` offset in previous versions, the date would be rolled *backwards* if date was in the same month as the quarter start date. @@ -699,7 +699,7 @@ For the ``QuarterBegin`` offset in previous versions, the date would be rolled In [3]: d = pd.Timestamp('2014-02-15') - In [4]: d + pd.offsets.QuarterBegin(n=0, month=2) + In [4]: d + pd.offsets.QuarterBegin(n=0, startingMonth=2) Out[4]: Timestamp('2014-02-01 00:00:00') This behavior has been corrected in version 0.18.0, which is consistent with @@ -708,7 +708,7 @@ other anchored offsets like ``MonthBegin`` and ``YearBegin``. .. ipython:: python d = pd.Timestamp('2014-02-15') - d + pd.offsets.QuarterBegin(n=0, month=2) + d + pd.offsets.QuarterBegin(n=0, startingMonth=2) .. _whatsnew_0180.breaking.resample: From 63a115228b3f6af9c8680c703a62c01247ff2517 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Wed, 31 Mar 2021 14:04:58 +0200 Subject: [PATCH 51/66] Update offset_frequency.rst --- doc/source/reference/offset_frequency.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/source/reference/offset_frequency.rst b/doc/source/reference/offset_frequency.rst index c5ed8d718bfb7..cd649cfa62a28 100644 --- a/doc/source/reference/offset_frequency.rst +++ b/doc/source/reference/offset_frequency.rst @@ -656,6 +656,7 @@ Properties BQuarterEnd.rule_code BQuarterEnd.n BQuarterEnd.month + BQuarterEnd.startingMonth Methods ~~~~~~~ @@ -691,6 +692,7 @@ Properties BQuarterBegin.rule_code BQuarterBegin.n BQuarterBegin.month + BQuarterBegin.startingMonth Methods ~~~~~~~ @@ -726,6 +728,7 @@ Properties QuarterEnd.rule_code QuarterEnd.n QuarterEnd.month + QuarterEnd.startingMonth Methods ~~~~~~~ @@ -761,6 +764,7 @@ Properties QuarterBegin.rule_code QuarterBegin.n QuarterBegin.month + QuarterBegin.startingMonth Methods ~~~~~~~ From f2410e7c8daa74d40f64a48d4443dfca5c34d92e Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Wed, 31 Mar 2021 15:40:48 +0200 Subject: [PATCH 52/66] Update docstrings --- pandas/_libs/tslibs/offsets.pyx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 8d2af137701a8..bae89009b1de3 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1999,6 +1999,8 @@ cdef class QuarterOffset(SingleConstructorOffset): month : int The calendar month number (1 for January) of the beginning or ending month in a custom-defined quarter to be used as an offset. + + .. versionadded:: 1.X.X startingMonth : int The calendar month number (1 for January) of the beginning or ending month in a custom-defined quarter to be used as an offset. @@ -2114,6 +2116,8 @@ cdef class BQuarterEnd(QuarterOffset): month : int, default 3 The calendar month number (3 for March) of the last month in a custom-defined business quarter to be used as an offset. + + .. versionadded:: 1.X.X startingMonth : int, default 3 The calendar month number (3 for March) of the last month in a custom-defined business quarter to be used as an offset. @@ -2158,6 +2162,8 @@ cdef class BQuarterBegin(QuarterOffset): month : int, default 1 The calendar month number (1 for January) of the first month in a custom-defined business quarter to be used as an offset. + + .. versionadded:: 1.X.X startingMonth : int, default 1 The calendar month number (1 for January) of the first month in a custom-defined business quarter to be used as an offset. @@ -2202,6 +2208,8 @@ cdef class QuarterEnd(QuarterOffset): month : int, default 3 The calendar month number (3 for March) of the last month in a custom-defined quarter to be used as an offset. + + .. versionadded:: 1.X.X startingMonth : int, default 3 The calendar month number (3 for March) of the last month in a custom-defined quarter to be used as an offset. @@ -2243,6 +2251,8 @@ cdef class QuarterBegin(QuarterOffset): month : int, default 1 The calendar month number (1 for January) of the first month in a custom-defined quarter to be used as an offset. + + .. versionadded:: 1.X.X startingMonth : int, default 1 The calendar month number (1 for January) of the first month in a custom-defined quarter to be used as an offset. From bc0d0c6f869aca85397002438f72d9d814cb739e Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Wed, 31 Mar 2021 18:52:34 +0200 Subject: [PATCH 53/66] whatsnew entry --- doc/source/whatsnew/v1.3.0.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/source/whatsnew/v1.3.0.rst b/doc/source/whatsnew/v1.3.0.rst index 1e723493a4cc8..f496ea0a128bb 100644 --- a/doc/source/whatsnew/v1.3.0.rst +++ b/doc/source/whatsnew/v1.3.0.rst @@ -458,6 +458,7 @@ Deprecations - Deprecated allowing partial failure in :meth:`Series.transform` and :meth:`DataFrame.transform` when ``func`` is list-like or dict-like and raises anything but ``TypeError``; ``func`` raising anything but a ``TypeError`` will raise in a future version (:issue:`40211`) - Deprecated support for ``np.ma.mrecords.MaskedRecords`` in the :class:`DataFrame` constructor, pass ``{name: data[name] for name in data.dtype.names}`` instead (:issue:`40363`) - Deprecated the use of ``**kwargs`` in :class:`.ExcelWriter`; use the keyword argument ``engine_kwargs`` instead (:issue:`40430`) +- Deprecated the use of keyword argument ``startingMonth`` in quarter-based offsets :class:`QuarterBegin`, :class:`QuarterEnd`, :class:`BQuarterBegin`, :class:`BQuarterEnd`; use ``month`` instead (:issue:`5307`) .. --------------------------------------------------------------------------- @@ -511,6 +512,7 @@ Datetimelike - Bug in :meth:`Timedelta.round`, :meth:`Timedelta.floor`, :meth:`Timedelta.ceil` for values near the implementation bounds of :class:`Timedelta` (:issue:`38964`) - Bug in :func:`date_range` incorrectly creating :class:`DatetimeIndex` containing ``NaT`` instead of raising ``OutOfBoundsDatetime`` in corner cases (:issue:`24124`) - Bug in :func:`infer_freq` incorrectly fails to infer 'H' frequency of :class:`DatetimeIndex` if the latter has a timezone and crosses DST boundaries (:issue:`39556`) +- Bug in offsets :class:`QuarterBegin` and :class:`BQuarterBegin` returning days that are not conventional quarter beginnings (:issue:`8435`) Timedelta ^^^^^^^^^ From f21921de4203ba5187b5321ade49b01c8d21d259 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Mon, 5 Apr 2021 21:22:04 +0200 Subject: [PATCH 54/66] Update offsets.pyx according to GH#39890 review --- pandas/_libs/tslibs/offsets.pyx | 40 ++++++++++++++++----------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index bae89009b1de3..e20814d566034 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1840,7 +1840,7 @@ cdef class YearOffset(SingleConstructorOffset): """ _attributes = tuple(["n", "normalize", "month"]) - # FIXME: python annotation here breaks things + # _default_month: int # FIXME: python annotation here breaks things cdef readonly: int month @@ -2000,35 +2000,32 @@ cdef class QuarterOffset(SingleConstructorOffset): The calendar month number (1 for January) of the beginning or ending month in a custom-defined quarter to be used as an offset. - .. versionadded:: 1.X.X + .. versionadded:: 1.3 startingMonth : int The calendar month number (1 for January) of the beginning or ending month in a custom-defined quarter to be used as an offset. - .. deprecated:: 1.X.X + .. deprecated:: 1.3 """ _attributes = tuple(["n", "normalize", "month"]) # TODO: Consider combining QuarterOffset and YearOffset __init__ at some # point. Also apply_index, is_on_offset, rule_code. - # FIXME: python annotation here breaks things - cdef readonly: int month - int startingMonth # Backwards compatibility - def __init__(self, n=1, normalize=False, month=None, - *, startingMonth=None): # Backwards compatibility + def __init__(self, n:int=1, normalize:bool=False, month:int=None, + *, startingMonth:int=None): # GH#5307 backwards compatibility BaseOffset.__init__(self, n, normalize) - # Backwards compatibility + # GH#5307 backwards compatibility if month and startingMonth and month != startingMonth: raise TypeError("Offset received both month and startingMonth") elif month is None and startingMonth is not None: warnings.warn( "startingMonth is deprecated, use month instead.", - DeprecationWarning, + FutureWarning, stacklevel=2 ) month = startingMonth @@ -2043,7 +2040,8 @@ cdef class QuarterOffset(SingleConstructorOffset): try: self.month = state.pop("month") except: - self.month = state.pop("startingMonth") # For legacy pickles + # Necessary for read_pickle of data pickled with pre-1.3 pandas + self.month = state.pop("startingMonth") self.n = state.pop("n") self.normalize = state.pop("normalize") self._cache = {} @@ -2117,12 +2115,12 @@ cdef class BQuarterEnd(QuarterOffset): The calendar month number (3 for March) of the last month in a custom-defined business quarter to be used as an offset. - .. versionadded:: 1.X.X + .. versionadded:: 1.3 startingMonth : int, default 3 The calendar month number (3 for March) of the last month in a custom-defined business quarter to be used as an offset. - .. deprecated:: 1.X.X + .. deprecated:: 1.3 Examples -------- @@ -2163,12 +2161,12 @@ cdef class BQuarterBegin(QuarterOffset): The calendar month number (1 for January) of the first month in a custom-defined business quarter to be used as an offset. - .. versionadded:: 1.X.X + .. versionadded:: 1.3 startingMonth : int, default 1 The calendar month number (1 for January) of the first month in a custom-defined business quarter to be used as an offset. - .. deprecated:: 1.X.X + .. deprecated:: 1.3 Examples -------- @@ -2209,12 +2207,12 @@ cdef class QuarterEnd(QuarterOffset): The calendar month number (3 for March) of the last month in a custom-defined quarter to be used as an offset. - .. versionadded:: 1.X.X + .. versionadded:: 1.3 startingMonth : int, default 3 The calendar month number (3 for March) of the last month in a custom-defined quarter to be used as an offset. - .. deprecated:: 1.X.X + .. deprecated:: 1.3 """ _default_month = 3 _from_name_month = 3 @@ -2224,8 +2222,8 @@ cdef class QuarterEnd(QuarterOffset): cdef readonly: int _period_dtype_code - def __init__(self, n=1, normalize=False, month=None, - *, startingMonth=None): # Backwards compatibility + def __init__(self, n:int=1, normalize:bool=False, month:int=None, + *, startingMonth:int=None): # GH#5307 backwards compatibility # Because QuarterEnd can be the freq for a Period, define its # _period_dtype_code at construction for performance QuarterOffset.__init__(self, n, normalize, month, @@ -2252,12 +2250,12 @@ cdef class QuarterBegin(QuarterOffset): The calendar month number (1 for January) of the first month in a custom-defined quarter to be used as an offset. - .. versionadded:: 1.X.X + .. versionadded:: 1.3 startingMonth : int, default 1 The calendar month number (1 for January) of the first month in a custom-defined quarter to be used as an offset. - .. deprecated:: 1.X.X + .. deprecated:: 1.3 """ _default_month = 1 _from_name_month = 1 From 448e0da5f03f24998c79472130180729b85013e3 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Mon, 5 Apr 2021 21:33:25 +0200 Subject: [PATCH 55/66] Update test_offsets.pyx according to GH#39890 review Update test_startingMonth_deprecation --- pandas/tests/tseries/offsets/test_offsets.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index 79250c7790390..75aa1a771bff6 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -884,6 +884,11 @@ def test_dateoffset_immutable(attribute): "BQuarterEnd", ], ) -def test_startingMonth_deprecation_warning(offset_type): - with tm.assert_produces_warning(DeprecationWarning): +def test_startingMonth_deprecation(offset_type): + # GH#5307 + with tm.assert_produces_warning(FutureWarning): eval(f"offsets.{offset_type}(startingMonth=1)") + + msg = "Offset received both month and startingMonth" + with pytest.raises(TypeError, match=msg): + eval(f"offsets.{offset_type}(startingMonth=1,month=2)") From fe07ea27c7ebe65bd9626c9c9901adc35b8ba420 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Mon, 5 Apr 2021 21:59:28 +0200 Subject: [PATCH 56/66] Update offsets.pyx --- pandas/_libs/tslibs/offsets.pyx | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index e20814d566034..04efca5063f65 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2014,6 +2014,7 @@ cdef class QuarterOffset(SingleConstructorOffset): cdef readonly: int month + int startingMonth # GH#5307 backwards compatibility def __init__(self, n:int=1, normalize:bool=False, month:int=None, *, startingMonth:int=None): # GH#5307 backwards compatibility From 5b2ec3fbf5c663a28ed470568b994763549bf1d0 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Mon, 5 Apr 2021 22:12:34 +0200 Subject: [PATCH 57/66] Update offsets.pyx --- pandas/_libs/tslibs/offsets.pyx | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 04efca5063f65..123bc7c9aa194 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2000,12 +2000,12 @@ cdef class QuarterOffset(SingleConstructorOffset): The calendar month number (1 for January) of the beginning or ending month in a custom-defined quarter to be used as an offset. - .. versionadded:: 1.3 + .. versionadded:: 1.3.0 startingMonth : int The calendar month number (1 for January) of the beginning or ending month in a custom-defined quarter to be used as an offset. - .. deprecated:: 1.3 + .. deprecated:: 1.3.0 """ _attributes = tuple(["n", "normalize", "month"]) @@ -2014,10 +2014,10 @@ cdef class QuarterOffset(SingleConstructorOffset): cdef readonly: int month - int startingMonth # GH#5307 backwards compatibility + # int startingMonth # GH#5307 backwards compatibility - def __init__(self, n:int=1, normalize:bool=False, month:int=None, - *, startingMonth:int=None): # GH#5307 backwards compatibility + def __init__(self, n: int=1, normalize: bool=False, month: int=None, + *, startingMonth: int=None): # GH#5307 backwards compatibility BaseOffset.__init__(self, n, normalize) # GH#5307 backwards compatibility @@ -2116,12 +2116,12 @@ cdef class BQuarterEnd(QuarterOffset): The calendar month number (3 for March) of the last month in a custom-defined business quarter to be used as an offset. - .. versionadded:: 1.3 + .. versionadded:: 1.3.0 startingMonth : int, default 3 The calendar month number (3 for March) of the last month in a custom-defined business quarter to be used as an offset. - .. deprecated:: 1.3 + .. deprecated:: 1.3.0 Examples -------- @@ -2162,12 +2162,12 @@ cdef class BQuarterBegin(QuarterOffset): The calendar month number (1 for January) of the first month in a custom-defined business quarter to be used as an offset. - .. versionadded:: 1.3 + .. versionadded:: 1.3.0 startingMonth : int, default 1 The calendar month number (1 for January) of the first month in a custom-defined business quarter to be used as an offset. - .. deprecated:: 1.3 + .. deprecated:: 1.3.0 Examples -------- @@ -2208,12 +2208,12 @@ cdef class QuarterEnd(QuarterOffset): The calendar month number (3 for March) of the last month in a custom-defined quarter to be used as an offset. - .. versionadded:: 1.3 + .. versionadded:: 1.3.0 startingMonth : int, default 3 The calendar month number (3 for March) of the last month in a custom-defined quarter to be used as an offset. - .. deprecated:: 1.3 + .. deprecated:: 1.3.0 """ _default_month = 3 _from_name_month = 3 @@ -2223,8 +2223,8 @@ cdef class QuarterEnd(QuarterOffset): cdef readonly: int _period_dtype_code - def __init__(self, n:int=1, normalize:bool=False, month:int=None, - *, startingMonth:int=None): # GH#5307 backwards compatibility + def __init__(self, n: int=1, normalize: bool=False, month: int=None, + *, startingMonth: int=None): # GH#5307 backwards compatibility # Because QuarterEnd can be the freq for a Period, define its # _period_dtype_code at construction for performance QuarterOffset.__init__(self, n, normalize, month, @@ -2251,12 +2251,12 @@ cdef class QuarterBegin(QuarterOffset): The calendar month number (1 for January) of the first month in a custom-defined quarter to be used as an offset. - .. versionadded:: 1.3 + .. versionadded:: 1.3.0 startingMonth : int, default 1 The calendar month number (1 for January) of the first month in a custom-defined quarter to be used as an offset. - .. deprecated:: 1.3 + .. deprecated:: 1.3.0 """ _default_month = 1 _from_name_month = 1 From 827ab65b6c2bf81b33a95e5f21691e18c3bbe3ce Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Mon, 5 Apr 2021 23:05:27 +0200 Subject: [PATCH 58/66] Update v1.3.0.rst Add quarter-based offsets' changes to the API breaking changes (Notable bug fixes) section --- doc/source/whatsnew/v1.3.0.rst | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/doc/source/whatsnew/v1.3.0.rst b/doc/source/whatsnew/v1.3.0.rst index f496ea0a128bb..01a9edd1fe801 100644 --- a/doc/source/whatsnew/v1.3.0.rst +++ b/doc/source/whatsnew/v1.3.0.rst @@ -351,6 +351,36 @@ However, floating point artifacts may now exist in the results when rolling over s.rolling(3).var() +.. _whatsnew_130.notable_bug_fixes.quarterbegin_default_anchor: + +Changed default periods in :class:`~pandas.tseries.offsets.QuarterBegin` and :class:`~pandas.tseries.offsets.BQuarterBegin` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Quarter-based time offset classes :class:`~pandas.tseries.offsets.QuarterEnd`, +:class:`~pandas.tseries.offsets.QuarterBegin`, :class:`~pandas.tseries.offsets.BQuarterEnd`, +:class:`~pandas.tseries.offsets.BQuarterBegin` now use ``month`` instead of ``startingMonth`` +as a time anchor parameter (:issue:`5307`). Its default value for :class:`~pandas.tseries.offsets.QuarterBegin` +and :class:`~pandas.tseries.offsets.BQuarterBegin` is now 1 (January) instead of 3 (March), +as a result these offsets are aligned with standard calendar quarters (:issue:`8435`). + +*pandas 1.2.x* + +.. code-block:: ipython + + In [1]: datetime.datetime(2014,10,10) + pd.tseries.offsets.QuarterBegin() + Out[2]: Timestamp('2014-12-01 00:00:00') + In [3]: datetime.datetime(2014,10,10) + pd.tseries.offsets.BQuarterBegin() + Out[4]: Timestamp('2014-12-01 00:00:00') + +*pandas 1.3.0* + +.. ipython:: python + + In [1]: datetime.datetime(2014,10,10) + pd.tseries.offsets.QuarterBegin() + Out[2]: Timestamp('2015-01-01 00:00:00') + In [3]: datetime.datetime(2014,10,10) + pd.tseries.offsets.BQuarterBegin() + Out[4]: Timestamp('2015-01-01 00:00:00') + .. _whatsnew_130.api_breaking.deps: Increased minimum versions for dependencies From f27b5ef382959b18fe35a817e22a8dac717be325 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Mon, 5 Apr 2021 23:09:24 +0200 Subject: [PATCH 59/66] 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 123bc7c9aa194..b81a3a9268325 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2014,7 +2014,6 @@ cdef class QuarterOffset(SingleConstructorOffset): cdef readonly: int month - # int startingMonth # GH#5307 backwards compatibility def __init__(self, n: int=1, normalize: bool=False, month: int=None, *, startingMonth: int=None): # GH#5307 backwards compatibility From 1441a295d35a102a03fa4b0cc18f2b6e59e7fd4e Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Mon, 5 Apr 2021 23:38:24 +0200 Subject: [PATCH 60/66] Update v1.3.0.rst --- doc/source/whatsnew/v1.3.0.rst | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/doc/source/whatsnew/v1.3.0.rst b/doc/source/whatsnew/v1.3.0.rst index 01a9edd1fe801..01032d840295a 100644 --- a/doc/source/whatsnew/v1.3.0.rst +++ b/doc/source/whatsnew/v1.3.0.rst @@ -363,22 +363,26 @@ as a time anchor parameter (:issue:`5307`). Its default value for :class:`~panda and :class:`~pandas.tseries.offsets.BQuarterBegin` is now 1 (January) instead of 3 (March), as a result these offsets are aligned with standard calendar quarters (:issue:`8435`). +.. ipython:: python + + from datetime import datetime + *pandas 1.2.x* .. code-block:: ipython - In [1]: datetime.datetime(2014,10,10) + pd.tseries.offsets.QuarterBegin() + In [1]: datetime(2014, 10, 10) + pd.tseries.offsets.QuarterBegin() Out[2]: Timestamp('2014-12-01 00:00:00') - In [3]: datetime.datetime(2014,10,10) + pd.tseries.offsets.BQuarterBegin() + In [3]: datetime(2014, 10, 10) + pd.tseries.offsets.BQuarterBegin() Out[4]: Timestamp('2014-12-01 00:00:00') *pandas 1.3.0* .. ipython:: python - In [1]: datetime.datetime(2014,10,10) + pd.tseries.offsets.QuarterBegin() + In [1]: datetime(2014, 10, 10) + pd.tseries.offsets.QuarterBegin() Out[2]: Timestamp('2015-01-01 00:00:00') - In [3]: datetime.datetime(2014,10,10) + pd.tseries.offsets.BQuarterBegin() + In [3]: datetime(2014, 10, 10) + pd.tseries.offsets.BQuarterBegin() Out[4]: Timestamp('2015-01-01 00:00:00') .. _whatsnew_130.api_breaking.deps: From 78756143c06fbbb25c01a9d1d6f6b29e885e03af Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Tue, 6 Apr 2021 09:26:27 +0200 Subject: [PATCH 61/66] Update offset_frequency.rst --- doc/source/reference/offset_frequency.rst | 4 ---- 1 file changed, 4 deletions(-) diff --git a/doc/source/reference/offset_frequency.rst b/doc/source/reference/offset_frequency.rst index cd649cfa62a28..c5ed8d718bfb7 100644 --- a/doc/source/reference/offset_frequency.rst +++ b/doc/source/reference/offset_frequency.rst @@ -656,7 +656,6 @@ Properties BQuarterEnd.rule_code BQuarterEnd.n BQuarterEnd.month - BQuarterEnd.startingMonth Methods ~~~~~~~ @@ -692,7 +691,6 @@ Properties BQuarterBegin.rule_code BQuarterBegin.n BQuarterBegin.month - BQuarterBegin.startingMonth Methods ~~~~~~~ @@ -728,7 +726,6 @@ Properties QuarterEnd.rule_code QuarterEnd.n QuarterEnd.month - QuarterEnd.startingMonth Methods ~~~~~~~ @@ -764,7 +761,6 @@ Properties QuarterBegin.rule_code QuarterBegin.n QuarterBegin.month - QuarterBegin.startingMonth Methods ~~~~~~~ From 688eaf629adb0e2920aeabc8d5eccb7e021e3b70 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Tue, 6 Apr 2021 10:38:23 +0200 Subject: [PATCH 62/66] Update v0.18.0.rst --- doc/source/whatsnew/v0.18.0.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/source/whatsnew/v0.18.0.rst b/doc/source/whatsnew/v0.18.0.rst index 829c04dac9f2d..88c6fe0c53069 100644 --- a/doc/source/whatsnew/v0.18.0.rst +++ b/doc/source/whatsnew/v0.18.0.rst @@ -686,6 +686,7 @@ when it is an anchor point (e.g., a quarter start date), and otherwise roll forward to the next anchor point. .. ipython:: python + :okwarning: d = pd.Timestamp('2014-02-01') d @@ -696,6 +697,7 @@ For the ``QuarterBegin`` offset in previous versions, the date would be rolled *backwards* if date was in the same month as the quarter start date. .. code-block:: ipython + :okwarning: In [3]: d = pd.Timestamp('2014-02-15') @@ -706,6 +708,7 @@ This behavior has been corrected in version 0.18.0, which is consistent with other anchored offsets like ``MonthBegin`` and ``YearBegin``. .. ipython:: python + :okwarning: d = pd.Timestamp('2014-02-15') d + pd.offsets.QuarterBegin(n=0, startingMonth=2) From c0f6d84655295001f6ed3f87fb47abe4b7a4ffb4 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Tue, 6 Apr 2021 10:40:29 +0200 Subject: [PATCH 63/66] Update v1.3.0.rst --- doc/source/whatsnew/v1.3.0.rst | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/doc/source/whatsnew/v1.3.0.rst b/doc/source/whatsnew/v1.3.0.rst index 01032d840295a..25a5193692aa0 100644 --- a/doc/source/whatsnew/v1.3.0.rst +++ b/doc/source/whatsnew/v1.3.0.rst @@ -363,26 +363,22 @@ as a time anchor parameter (:issue:`5307`). Its default value for :class:`~panda and :class:`~pandas.tseries.offsets.BQuarterBegin` is now 1 (January) instead of 3 (March), as a result these offsets are aligned with standard calendar quarters (:issue:`8435`). -.. ipython:: python - - from datetime import datetime - *pandas 1.2.x* .. code-block:: ipython - In [1]: datetime(2014, 10, 10) + pd.tseries.offsets.QuarterBegin() + In [1]: pd.Timestamp(2014, 10, 10) + pd.tseries.offsets.QuarterBegin() Out[2]: Timestamp('2014-12-01 00:00:00') - In [3]: datetime(2014, 10, 10) + pd.tseries.offsets.BQuarterBegin() + In [3]: pd.Timestamp(2014, 10, 10) + pd.tseries.offsets.BQuarterBegin() Out[4]: Timestamp('2014-12-01 00:00:00') *pandas 1.3.0* -.. ipython:: python +.. code-block:: ipython - In [1]: datetime(2014, 10, 10) + pd.tseries.offsets.QuarterBegin() + In [1]: pd.Timestamp(2014, 10, 10) + pd.tseries.offsets.QuarterBegin() Out[2]: Timestamp('2015-01-01 00:00:00') - In [3]: datetime(2014, 10, 10) + pd.tseries.offsets.BQuarterBegin() + In [3]: pd.Timestamp(2014, 10, 10) + pd.tseries.offsets.BQuarterBegin() Out[4]: Timestamp('2015-01-01 00:00:00') .. _whatsnew_130.api_breaking.deps: From a5416a1412a74ea5094158a44e510b7f5d1ae875 Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Tue, 6 Apr 2021 12:22:56 +0200 Subject: [PATCH 64/66] Update v0.18.0.rst --- doc/source/whatsnew/v0.18.0.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/whatsnew/v0.18.0.rst b/doc/source/whatsnew/v0.18.0.rst index 88c6fe0c53069..349a718cf2172 100644 --- a/doc/source/whatsnew/v0.18.0.rst +++ b/doc/source/whatsnew/v0.18.0.rst @@ -697,7 +697,6 @@ For the ``QuarterBegin`` offset in previous versions, the date would be rolled *backwards* if date was in the same month as the quarter start date. .. code-block:: ipython - :okwarning: In [3]: d = pd.Timestamp('2014-02-15') From 22c779f8a2dc3318f04a2f4d37fa0b0a4bd76c6a Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Thu, 6 May 2021 09:32:42 +0200 Subject: [PATCH 65/66] Update v1.3.0.rst --- doc/source/whatsnew/v1.3.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.3.0.rst b/doc/source/whatsnew/v1.3.0.rst index 046033344f88a..618045b6ffa7d 100644 --- a/doc/source/whatsnew/v1.3.0.rst +++ b/doc/source/whatsnew/v1.3.0.rst @@ -466,7 +466,7 @@ Changed default periods in :class:`~pandas.tseries.offsets.QuarterBegin` and :cl Quarter-based time offset classes :class:`~pandas.tseries.offsets.QuarterEnd`, :class:`~pandas.tseries.offsets.QuarterBegin`, :class:`~pandas.tseries.offsets.BQuarterEnd`, :class:`~pandas.tseries.offsets.BQuarterBegin` now use ``month`` instead of ``startingMonth`` -as a time anchor parameter (:issue:`5307`). Its default value for :class:`~pandas.tseries.offsets.QuarterBegin` +as a time anchor parameter (:issue:`5307`). The default value for :class:`~pandas.tseries.offsets.QuarterBegin` and :class:`~pandas.tseries.offsets.BQuarterBegin` is now 1 (January) instead of 3 (March), as a result these offsets are aligned with standard calendar quarters (:issue:`8435`). From 384cb82c313035afc238ae7bc113374283c05e8e Mon Sep 17 00:00:00 2001 From: Pawel Kranzberg Date: Thu, 6 May 2021 09:50:03 +0200 Subject: [PATCH 66/66] Update offsets.pyx --- pandas/_libs/tslibs/offsets.pyx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index b81a3a9268325..be9d4a7ac04c6 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2016,17 +2016,17 @@ cdef class QuarterOffset(SingleConstructorOffset): int month def __init__(self, n: int=1, normalize: bool=False, month: int=None, - *, startingMonth: int=None): # GH#5307 backwards compatibility + *, startingMonth: int=None): + # GH#5307 startingMonth retained for backwards compatibility BaseOffset.__init__(self, n, normalize) - # GH#5307 backwards compatibility + # GH#5307 startingMonth retained for backwards compatibility if month and startingMonth and month != startingMonth: raise TypeError("Offset received both month and startingMonth") elif month is None and startingMonth is not None: warnings.warn( "startingMonth is deprecated, use month instead.", - FutureWarning, - stacklevel=2 + FutureWarning, stacklevel=2 ) month = startingMonth