From 60bc2b2335cf8b3b42486b2c1bdcea87df7ff0a8 Mon Sep 17 00:00:00 2001 From: gboeker Date: Wed, 27 Mar 2024 12:06:21 -0400 Subject: [PATCH 1/6] remove 'or tuple' --- pandas/core/frame.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 501901e5b3593..e555709a38093 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -5999,8 +5999,8 @@ def reset_index( names : int, str or 1-dimensional list, default None Using the given string, rename the DataFrame column which contains the - index data. If the DataFrame has a MultiIndex, this has to be a list or - tuple with length equal to the number of levels. + index data. If the DataFrame has a MultiIndex, this has to be a list + with length equal to the number of levels. .. versionadded:: 1.5.0 From b9ffd56445425921f70b9f29178d93f22c8e36f4 Mon Sep 17 00:00:00 2001 From: gboeker <68177766+gboeker@users.noreply.github.com> Date: Wed, 27 Mar 2024 12:42:24 -0400 Subject: [PATCH 2/6] remove trailing space --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 9852c0f8f6a47..50a93994dc76b 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -6011,7 +6011,7 @@ def reset_index( names : int, str or 1-dimensional list, default None Using the given string, rename the DataFrame column which contains the - index data. If the DataFrame has a MultiIndex, this has to be a list + index data. If the DataFrame has a MultiIndex, this has to be a list with length equal to the number of levels. .. versionadded:: 1.5.0 From c854f97ca5d13ac7e9d696c2260999254f88f93a Mon Sep 17 00:00:00 2001 From: gboeker Date: Mon, 1 Apr 2024 14:41:33 -0400 Subject: [PATCH 3/6] rename startingMonth to starting_month --- ci/code_checks.sh | 12 +- doc/source/reference/offset_frequency.rst | 12 +- pandas/_libs/tslibs/fields.pyx | 4 +- pandas/_libs/tslibs/offsets.pyi | 6 +- pandas/_libs/tslibs/offsets.pyx | 134 +++++++++--------- pandas/_libs/tslibs/timestamps.pyx | 2 +- pandas/conftest.py | 2 +- pandas/core/arrays/datetimes.py | 2 +- pandas/tests/arithmetic/test_datetime64.py | 4 +- pandas/tests/arithmetic/test_period.py | 10 +- .../indexes/datetimes/test_date_range.py | 6 +- .../tests/io/generate_legacy_storage_files.py | 2 +- pandas/tests/resample/test_period_index.py | 2 +- pandas/tests/scalar/period/test_arithmetic.py | 2 +- pandas/tests/scalar/period/test_period.py | 6 +- .../tseries/offsets/test_business_quarter.py | 98 ++++++------- pandas/tests/tseries/offsets/test_common.py | 4 +- pandas/tests/tseries/offsets/test_fiscal.py | 124 ++++++++-------- pandas/tests/tseries/offsets/test_offsets.py | 4 +- pandas/tests/tseries/offsets/test_quarter.py | 104 +++++++------- pandas/tests/tslibs/test_libfrequencies.py | 4 +- 21 files changed, 273 insertions(+), 271 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 0c4e6641444f1..29e5c9f5dccc3 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -865,7 +865,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.tseries.offsets.BQuarterBegin.nanos GL08" \ -i "pandas.tseries.offsets.BQuarterBegin.normalize GL08" \ -i "pandas.tseries.offsets.BQuarterBegin.rule_code GL08" \ - -i "pandas.tseries.offsets.BQuarterBegin.startingMonth GL08" \ + -i "pandas.tseries.offsets.BQuarterBegin.starting_month GL08" \ -i "pandas.tseries.offsets.BQuarterEnd PR02" \ -i "pandas.tseries.offsets.BQuarterEnd.copy SA01" \ -i "pandas.tseries.offsets.BQuarterEnd.freqstr SA01" \ @@ -876,7 +876,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.tseries.offsets.BQuarterEnd.nanos GL08" \ -i "pandas.tseries.offsets.BQuarterEnd.normalize GL08" \ -i "pandas.tseries.offsets.BQuarterEnd.rule_code GL08" \ - -i "pandas.tseries.offsets.BQuarterEnd.startingMonth GL08" \ + -i "pandas.tseries.offsets.BQuarterEnd.starting_month GL08" \ -i "pandas.tseries.offsets.BYearBegin PR02" \ -i "pandas.tseries.offsets.BYearBegin.copy SA01" \ -i "pandas.tseries.offsets.BYearBegin.freqstr SA01" \ @@ -1048,7 +1048,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.tseries.offsets.FY5253.nanos GL08" \ -i "pandas.tseries.offsets.FY5253.normalize GL08" \ -i "pandas.tseries.offsets.FY5253.rule_code GL08" \ - -i "pandas.tseries.offsets.FY5253.startingMonth GL08" \ + -i "pandas.tseries.offsets.FY5253.starting_month GL08" \ -i "pandas.tseries.offsets.FY5253.variation GL08" \ -i "pandas.tseries.offsets.FY5253.weekday GL08" \ -i "pandas.tseries.offsets.FY5253Quarter PR02" \ @@ -1064,7 +1064,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.tseries.offsets.FY5253Quarter.normalize GL08" \ -i "pandas.tseries.offsets.FY5253Quarter.qtr_with_extra_week GL08" \ -i "pandas.tseries.offsets.FY5253Quarter.rule_code GL08" \ - -i "pandas.tseries.offsets.FY5253Quarter.startingMonth GL08" \ + -i "pandas.tseries.offsets.FY5253Quarter.starting_month GL08" \ -i "pandas.tseries.offsets.FY5253Quarter.variation GL08" \ -i "pandas.tseries.offsets.FY5253Quarter.weekday GL08" \ -i "pandas.tseries.offsets.FY5253Quarter.year_has_extra_week GL08" \ @@ -1160,7 +1160,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.tseries.offsets.QuarterBegin.nanos GL08" \ -i "pandas.tseries.offsets.QuarterBegin.normalize GL08" \ -i "pandas.tseries.offsets.QuarterBegin.rule_code GL08" \ - -i "pandas.tseries.offsets.QuarterBegin.startingMonth GL08" \ + -i "pandas.tseries.offsets.QuarterBegin.starting_month GL08" \ -i "pandas.tseries.offsets.QuarterEnd PR02" \ -i "pandas.tseries.offsets.QuarterEnd.copy SA01" \ -i "pandas.tseries.offsets.QuarterEnd.freqstr SA01" \ @@ -1171,7 +1171,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.tseries.offsets.QuarterEnd.nanos GL08" \ -i "pandas.tseries.offsets.QuarterEnd.normalize GL08" \ -i "pandas.tseries.offsets.QuarterEnd.rule_code GL08" \ - -i "pandas.tseries.offsets.QuarterEnd.startingMonth GL08" \ + -i "pandas.tseries.offsets.QuarterEnd.starting_month GL08" \ -i "pandas.tseries.offsets.Second PR02" \ -i "pandas.tseries.offsets.Second.copy SA01" \ -i "pandas.tseries.offsets.Second.freqstr SA01" \ diff --git a/doc/source/reference/offset_frequency.rst b/doc/source/reference/offset_frequency.rst index 8bb2c6ffe73be..f05a436c28a4e 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.starting_month Methods ~~~~~~~ @@ -690,7 +690,7 @@ Properties BQuarterBegin.normalize BQuarterBegin.rule_code BQuarterBegin.n - BQuarterBegin.startingMonth + BQuarterBegin.starting_month Methods ~~~~~~~ @@ -725,7 +725,7 @@ Properties QuarterEnd.normalize QuarterEnd.rule_code QuarterEnd.n - QuarterEnd.startingMonth + QuarterEnd.starting_month Methods ~~~~~~~ @@ -760,7 +760,7 @@ Properties QuarterBegin.normalize QuarterBegin.rule_code QuarterBegin.n - QuarterBegin.startingMonth + QuarterBegin.starting_month Methods ~~~~~~~ @@ -935,7 +935,7 @@ Properties FY5253.normalize FY5253.rule_code FY5253.n - FY5253.startingMonth + FY5253.starting_month FY5253.variation FY5253.weekday @@ -975,7 +975,7 @@ Properties FY5253Quarter.rule_code FY5253Quarter.n FY5253Quarter.qtr_with_extra_week - FY5253Quarter.startingMonth + FY5253Quarter.starting_month FY5253Quarter.variation FY5253Quarter.weekday diff --git a/pandas/_libs/tslibs/fields.pyx b/pandas/_libs/tslibs/fields.pyx index ff4fb4d635d17..0d2d7d2548e71 100644 --- a/pandas/_libs/tslibs/fields.pyx +++ b/pandas/_libs/tslibs/fields.pyx @@ -249,8 +249,8 @@ def get_start_end_field( is_business = freqstr[0] == "B" # YearBegin(), BYearBegin() use month = starting month of year. - # QuarterBegin(), BQuarterBegin() use startingMonth = starting - # month of year. Other offsets use month, startingMonth as ending + # QuarterBegin(), BQuarterBegin() use starting_month = starting + # month of year. Other offsets use month, starting_month as ending # month of year. if (freqstr[0:2] in ["MS", "QS", "YS"]) or ( diff --git a/pandas/_libs/tslibs/offsets.pyi b/pandas/_libs/tslibs/offsets.pyi index 3f942d6aa3622..9def4afb3ed34 100644 --- a/pandas/_libs/tslibs/offsets.pyi +++ b/pandas/_libs/tslibs/offsets.pyi @@ -161,7 +161,7 @@ class YearBegin(YearOffset): ... class QuarterOffset(SingleConstructorOffset): def __init__( - self, n: int = ..., normalize: bool = ..., startingMonth: int | None = ... + self, n: int = ..., normalize: bool = ..., starting_month: int | None = ... ) -> None: ... class BQuarterEnd(QuarterOffset): ... @@ -203,7 +203,7 @@ class FY5253Mixin(SingleConstructorOffset): n: int = ..., normalize: bool = ..., weekday: int = ..., - startingMonth: int = ..., + starting_month: int = ..., variation: Literal["nearest", "last"] = ..., ) -> None: ... @@ -215,7 +215,7 @@ class FY5253Quarter(FY5253Mixin): n: int = ..., normalize: bool = ..., weekday: int = ..., - startingMonth: int = ..., + starting_month: int = ..., qtr_with_extra_week: int = ..., variation: Literal["nearest", "last"] = ..., ) -> None: ... diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index e36abdf0ad971..4dd2f8d111d05 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -438,7 +438,7 @@ cdef class BaseOffset: >>> pd.offsets.FY5253Quarter().kwds {'weekday': 0, - 'startingMonth': 1, + 'starting_month': 1, 'qtr_with_extra_week': 1, 'variation': 'nearest'} """ @@ -2657,27 +2657,27 @@ cdef class YearBegin(YearOffset): # Quarter-Based Offset Classes cdef class QuarterOffset(SingleConstructorOffset): - _attributes = tuple(["n", "normalize", "startingMonth"]) + _attributes = tuple(["n", "normalize", "starting_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 + # starting_month vs month attr names are resolved # FIXME(cython#4446): python annotation here gives compile-time errors # _default_starting_month: int # _from_name_starting_month: int cdef readonly: - int startingMonth + int starting_month - def __init__(self, n=1, normalize=False, startingMonth=None): + def __init__(self, n=1, normalize=False, starting_month=None): BaseOffset.__init__(self, n, normalize) - if startingMonth is None: - startingMonth = self._default_starting_month - self.startingMonth = startingMonth + if starting_month is None: + starting_month = self._default_starting_month + self.starting_month = starting_month cpdef __setstate__(self, state): - self.startingMonth = state.pop("startingMonth") + self.starting_month = state.pop("starting_month") self.n = state.pop("n") self.normalize = state.pop("normalize") @@ -2685,21 +2685,21 @@ cdef class QuarterOffset(SingleConstructorOffset): def _from_name(cls, suffix=None): kwargs = {} if suffix: - kwargs["startingMonth"] = MONTH_TO_CAL_NUM[suffix] + kwargs["starting_month"] = MONTH_TO_CAL_NUM[suffix] else: if cls._from_name_starting_month is not None: - kwargs["startingMonth"] = cls._from_name_starting_month + kwargs["starting_month"] = cls._from_name_starting_month return cls(**kwargs) @property def rule_code(self) -> str: - month = MONTH_ALIASES[self.startingMonth] + month = MONTH_ALIASES[self.starting_month] return f"{self._prefix}-{month}" 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.starting_month) % 3 return mod_month == 0 and dt.day == self._get_offset_day(dt) @apply_wraps @@ -2709,9 +2709,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.starting_month % 3 qtrs = roll_qtrday( - other, self.n, self.startingMonth, day_opt=self._day_opt, modby=3 + other, self.n, self.starting_month, day_opt=self._day_opt, modby=3 ) months = qtrs * 3 - months_since return shift_month(other, months, self._day_opt) @@ -2721,7 +2721,7 @@ cdef class QuarterOffset(SingleConstructorOffset): shifted = shift_quarters( dtarr.view("i8"), self.n, - self.startingMonth, + self.starting_month, self._day_opt, modby=3, reso=reso, @@ -2733,9 +2733,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, ... + starting_month = 1 corresponds to dates like 1/31/2007, 4/30/2007, ... + starting_month = 2 corresponds to dates like 2/28/2007, 5/31/2007, ... + starting_month = 3 corresponds to dates like 3/30/2007, 6/29/2007, ... Parameters ---------- @@ -2743,7 +2743,7 @@ cdef class BQuarterEnd(QuarterOffset): The number of quarters represented. normalize : bool, default False Normalize start/end dates to midnight before generating date range. - startingMonth : int, default 3 + starting_month : int, default 3 A specific integer for the month of the year from which we start quarters. See Also @@ -2758,9 +2758,9 @@ cdef class BQuarterEnd(QuarterOffset): 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, starting_month=2) Timestamp('2020-05-29 05:01:15') - >>> ts + BQuarterEnd(startingMonth=2) + >>> ts + BQuarterEnd(starting_month=2) Timestamp('2020-05-29 05:01:15') """ _output_name = "BusinessQuarterEnd" @@ -2774,9 +2774,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, ... + starting_month = 1 corresponds to dates like 1/01/2007, 4/01/2007, ... + starting_month = 2 corresponds to dates like 2/01/2007, 5/01/2007, ... + starting_month = 3 corresponds to dates like 3/01/2007, 6/01/2007, ... Parameters ---------- @@ -2784,7 +2784,7 @@ cdef class BQuarterBegin(QuarterOffset): The number of quarters represented. normalize : bool, default False Normalize start/end dates to midnight before generating date range. - startingMonth : int, default 3 + starting_month : int, default 3 A specific integer for the month of the year from which we start quarters. See Also @@ -2799,7 +2799,7 @@ cdef class BQuarterBegin(QuarterOffset): Timestamp('2020-06-01 05:01:15') >>> ts + BQuarterBegin(2) Timestamp('2020-09-01 05:01:15') - >>> ts + BQuarterBegin(startingMonth=2) + >>> ts + BQuarterBegin(starting_month=2) Timestamp('2020-08-03 05:01:15') >>> ts + BQuarterBegin(-1) Timestamp('2020-03-02 05:01:15') @@ -2815,9 +2815,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, ... + starting_month = 1 corresponds to dates like 1/31/2007, 4/30/2007, ... + starting_month = 2 corresponds to dates like 2/28/2007, 5/31/2007, ... + starting_month = 3 corresponds to dates like 3/31/2007, 6/30/2007, ... Parameters ---------- @@ -2825,7 +2825,7 @@ cdef class QuarterEnd(QuarterOffset): The number of quarters represented. normalize : bool, default False Normalize start/end dates to midnight before generating date range. - startingMonth : int, default 3 + starting_month : int, default 3 A specific integer for the month of the year from which we start quarters. See Also @@ -2845,20 +2845,20 @@ 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, starting_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, startingMonth) - self._period_dtype_code = PeriodDtypeCode.Q_DEC + self.startingMonth % 12 + QuarterOffset.__init__(self, n, normalize, starting_month) + self._period_dtype_code = PeriodDtypeCode.Q_DEC + self.starting_month % 12 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, ... + starting_month = 1 corresponds to dates like 1/01/2007, 4/01/2007, ... + starting_month = 2 corresponds to dates like 2/01/2007, 5/01/2007, ... + starting_month = 3 corresponds to dates like 3/01/2007, 6/01/2007, ... Parameters ---------- @@ -2866,7 +2866,7 @@ cdef class QuarterBegin(QuarterOffset): The number of quarters represented. normalize : bool, default False Normalize start/end dates to midnight before generating date range. - startingMonth : int, default 3 + starting_month : int, default 3 A specific integer for the month of the year from which we start quarters. See Also @@ -3600,15 +3600,15 @@ cdef class LastWeekOfMonth(WeekOfMonthMixin): cdef class FY5253Mixin(SingleConstructorOffset): cdef readonly: - int startingMonth + int starting_month int weekday str variation def __init__( - self, n=1, normalize=False, weekday=0, startingMonth=1, variation="nearest" + self, n=1, normalize=False, weekday=0, starting_month=1, variation="nearest" ): BaseOffset.__init__(self, n, normalize) - self.startingMonth = startingMonth + self.starting_month = starting_month self.weekday = weekday self.variation = variation @@ -3641,7 +3641,7 @@ cdef class FY5253Mixin(SingleConstructorOffset): def get_rule_code_suffix(self) -> str: prefix = self._get_suffix_prefix() - month = MONTH_ALIASES[self.startingMonth] + month = MONTH_ALIASES[self.starting_month] weekday = int_to_weekday[self.weekday] return f"{prefix}-{month}-{weekday}" @@ -3685,7 +3685,7 @@ cdef class FY5253(FY5253Mixin): - 5 is Saturday - 6 is Sunday. - startingMonth : int {1, 2, ... 12}, default 1 + starting_month : int {1, 2, ... 12}, default 1 The month in which the fiscal year ends. variation : str, default "nearest" @@ -3708,23 +3708,23 @@ cdef class FY5253(FY5253Mixin): >>> ts + pd.offsets.FY5253() Timestamp('2022-01-31 00:00:00') - By the parameter ``startingMonth`` we can specify + By the parameter ``starting_month`` we can specify the month in which fiscal years end. >>> ts = pd.Timestamp(2022, 1, 1) - >>> ts + pd.offsets.FY5253(startingMonth=3) + >>> ts + pd.offsets.FY5253(starting_month=3) Timestamp('2022-03-28 00:00:00') 52-53 week fiscal year can be specified by ``weekday`` and ``variation`` parameters. >>> ts = pd.Timestamp(2022, 1, 1) - >>> ts + pd.offsets.FY5253(weekday=5, startingMonth=12, variation="last") + >>> ts + pd.offsets.FY5253(weekday=5, starting_month=12, variation="last") Timestamp('2022-12-31 00:00:00') """ _prefix = "RE" - _attributes = tuple(["n", "normalize", "weekday", "startingMonth", "variation"]) + _attributes = tuple(["n", "normalize", "weekday", "starting_month", "variation"]) def is_on_offset(self, dt: datetime) -> bool: if self.normalize and not _is_normalized(dt): @@ -3743,9 +3743,9 @@ cdef class FY5253(FY5253Mixin): norm = Timestamp(other).normalize() n = self.n - prev_year = self.get_year_end(datetime(other.year - 1, self.startingMonth, 1)) - cur_year = self.get_year_end(datetime(other.year, self.startingMonth, 1)) - next_year = self.get_year_end(datetime(other.year + 1, self.startingMonth, 1)) + prev_year = self.get_year_end(datetime(other.year - 1, self.starting_month, 1)) + cur_year = self.get_year_end(datetime(other.year, self.starting_month, 1)) + next_year = self.get_year_end(datetime(other.year + 1, self.starting_month, 1)) prev_year = localize_pydatetime(prev_year, other.tzinfo) cur_year = localize_pydatetime(cur_year, other.tzinfo) @@ -3781,7 +3781,7 @@ cdef class FY5253(FY5253Mixin): else: assert False - shifted = datetime(other.year + n, self.startingMonth, 1) + shifted = datetime(other.year + n, self.starting_month, 1) result = self.get_year_end(shifted) result = datetime( result.year, @@ -3797,8 +3797,8 @@ cdef class FY5253(FY5253Mixin): def get_year_end(self, dt: datetime) -> datetime: assert dt.tzinfo is None - dim = get_days_in_month(dt.year, self.startingMonth) - target_date = datetime(dt.year, self.startingMonth, dim) + dim = get_days_in_month(dt.year, self.starting_month) + target_date = datetime(dt.year, self.starting_month, dim) wkday_diff = self.weekday - target_date.weekday() if wkday_diff == 0: # year_end is the same for "last" and "nearest" cases @@ -3821,7 +3821,7 @@ cdef class FY5253(FY5253Mixin): return target_date + timedelta(days_forward - 7) @classmethod - def _parse_suffix(cls, varion_code, startingMonth_code, weekday_code): + def _parse_suffix(cls, varion_code, starting_month_code, weekday_code): if varion_code == "N": variation = "nearest" elif varion_code == "L": @@ -3829,12 +3829,12 @@ cdef class FY5253(FY5253Mixin): else: raise ValueError(f"Unable to parse varion_code: {varion_code}") - startingMonth = MONTH_TO_CAL_NUM[startingMonth_code] + starting_month = MONTH_TO_CAL_NUM[starting_month_code] weekday = weekday_to_int[weekday_code] return { "weekday": weekday, - "startingMonth": startingMonth, + "starting_month": starting_month, "variation": variation, } @@ -3867,9 +3867,9 @@ cdef class FY5253Quarter(FY5253Mixin): X is a specific day of the week. Y is a certain month of the year - 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, ... + starting_month = 1 corresponds to dates like 1/31/2007, 4/30/2007, ... + starting_month = 2 corresponds to dates like 2/28/2007, 5/31/2007, ... + starting_month = 3 corresponds to dates like 3/30/2007, 6/29/2007, ... Parameters ---------- @@ -3888,7 +3888,7 @@ cdef class FY5253Quarter(FY5253Mixin): - 5 is Saturday - 6 is Sunday. - startingMonth : int {1, 2, ..., 12}, default 1 + starting_month : int {1, 2, ..., 12}, default 1 The month in which fiscal years end. qtr_with_extra_week : int {1, 2, 3, 4}, default 1 @@ -3915,18 +3915,18 @@ cdef class FY5253Quarter(FY5253Mixin): >>> ts + pd.offsets.FY5253Quarter() Timestamp('2022-01-31 00:00:00') - By the parameter ``startingMonth`` we can specify + By the parameter ``starting_month`` we can specify the month in which fiscal years end. >>> ts = pd.Timestamp(2022, 1, 1) - >>> ts + pd.offsets.FY5253Quarter(startingMonth=3) + >>> ts + pd.offsets.FY5253Quarter(starting_month=3) Timestamp('2022-03-28 00:00:00') Business quarters for 52-53 week fiscal year can be specified by ``weekday`` and ``variation`` parameters. >>> ts = pd.Timestamp(2022, 1, 1) - >>> ts + pd.offsets.FY5253Quarter(weekday=5, startingMonth=12, variation="last") + >>> ts + pd.offsets.FY5253Quarter(weekday=5, starting_month=12, variation="last") Timestamp('2022-04-02 00:00:00') """ @@ -3936,7 +3936,7 @@ cdef class FY5253Quarter(FY5253Mixin): "n", "normalize", "weekday", - "startingMonth", + "starting_month", "qtr_with_extra_week", "variation", ] @@ -3950,12 +3950,12 @@ cdef class FY5253Quarter(FY5253Mixin): n=1, normalize=False, weekday=0, - startingMonth=1, + starting_month=1, qtr_with_extra_week=1, variation="nearest", ): FY5253Mixin.__init__( - self, n, normalize, weekday, startingMonth, variation + self, n, normalize, weekday, starting_month, variation ) self.qtr_with_extra_week = qtr_with_extra_week @@ -3966,7 +3966,7 @@ cdef class FY5253Quarter(FY5253Mixin): @cache_readonly def _offset(self): return FY5253( - startingMonth=self.startingMonth, + starting_month=self.starting_month, weekday=self.weekday, variation=self.variation, ) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index d4cd90613ca5b..e9ef24fcd1634 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -578,7 +578,7 @@ cdef class _Timestamp(ABCTimestamp): if freq: kwds = freq.kwds - month_kw = kwds.get("startingMonth", kwds.get("month", 12)) + month_kw = kwds.get("starting_month", kwds.get("month", 12)) freqstr = freq.freqstr else: month_kw = 12 diff --git a/pandas/conftest.py b/pandas/conftest.py index 34489bb70575a..330f27963c293 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -228,7 +228,7 @@ def pytest_collection_modifyitems(items, config) -> None: cls, n=st.integers(-24, 24), normalize=st.booleans(), - startingMonth=st.integers(min_value=1, max_value=12), + starting_month=st.integers(min_value=1, max_value=12), ), ) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index d446407ec3d01..ad4f6b12879aa 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -143,7 +143,7 @@ def f(self): month_kw = 12 if freq: kwds = freq.kwds - month_kw = kwds.get("startingMonth", kwds.get("month", 12)) + month_kw = kwds.get("starting_month", kwds.get("month", 12)) result = fields.get_start_end_field( values, field, self.freqstr, month_kw, reso=self._creso diff --git a/pandas/tests/arithmetic/test_datetime64.py b/pandas/tests/arithmetic/test_datetime64.py index da36b61d465a1..588357a92e707 100644 --- a/pandas/tests/arithmetic/test_datetime64.py +++ b/pandas/tests/arithmetic/test_datetime64.py @@ -1406,12 +1406,12 @@ def test_dt64arr_add_sub_relativedelta_offsets(self, box_with_array, unit): "FY5253Quarter", { "qtr_with_extra_week": 1, - "startingMonth": 1, + "starting_month": 1, "weekday": 2, "variation": "nearest", }, ), - ("FY5253", {"weekday": 0, "startingMonth": 2, "variation": "nearest"}), + ("FY5253", {"weekday": 0, "starting_month": 2, "variation": "nearest"}), ("WeekOfMonth", {"weekday": 2, "week": 2}), "Easter", ("DateOffset", {"day": 4}), diff --git a/pandas/tests/arithmetic/test_period.py b/pandas/tests/arithmetic/test_period.py index 18f1993c198df..820a6fcbce59c 100644 --- a/pandas/tests/arithmetic/test_period.py +++ b/pandas/tests/arithmetic/test_period.py @@ -702,7 +702,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, "starting_month"), (pd.offsets.MonthEnd, None), (pd.offsets.Week, "weekday"), ], @@ -872,8 +872,8 @@ def test_pi_add_offset_array(self, performance_warning, 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, starting_month=12), + pd.offsets.QuarterEnd(n=-2, starting_month=12), ] ) expected = PeriodIndex([Period("2015Q2"), Period("2015Q4")]).astype(object) @@ -903,8 +903,8 @@ def test_pi_sub_offset_array(self, performance_warning, 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, starting_month=12), + pd.offsets.QuarterEnd(n=-2, starting_month=12), ] ) diff --git a/pandas/tests/indexes/datetimes/test_date_range.py b/pandas/tests/indexes/datetimes/test_date_range.py index 43fcfd1e59670..00796ff07b865 100644 --- a/pandas/tests/indexes/datetimes/test_date_range.py +++ b/pandas/tests/indexes/datetimes/test_date_range.py @@ -1672,7 +1672,7 @@ def test_date_range_negative_freq_month_end(self, unit): assert rng.freq == "-2ME" def test_date_range_fy5253(self, unit): - freq = offsets.FY5253(startingMonth=1, weekday=3, variation="nearest") + freq = offsets.FY5253(starting_month=1, weekday=3, variation="nearest") dti = date_range( start="2013-01-01", periods=2, @@ -1688,8 +1688,8 @@ def test_date_range_fy5253(self, unit): @pytest.mark.parametrize( "freqstr,offset", [ - ("QS", offsets.QuarterBegin(startingMonth=1)), - ("BQE", offsets.BQuarterEnd(startingMonth=12)), + ("QS", offsets.QuarterBegin(starting_month=1)), + ("BQE", offsets.BQuarterEnd(starting_month=12)), ("W-SUN", offsets.Week(weekday=6)), ], ) diff --git a/pandas/tests/io/generate_legacy_storage_files.py b/pandas/tests/io/generate_legacy_storage_files.py index 9bfd8eb9d51d5..24d24083448fd 100644 --- a/pandas/tests/io/generate_legacy_storage_files.py +++ b/pandas/tests/io/generate_legacy_storage_files.py @@ -266,7 +266,7 @@ def create_pickle_data(): "Week_Tues": Week(2, normalize=False, weekday=1), "WeekOfMonth": WeekOfMonth(week=3, weekday=4), "LastWeekOfMonth": LastWeekOfMonth(n=1, weekday=3), - "FY5253": FY5253(n=2, weekday=6, startingMonth=7, variation="last"), + "FY5253": FY5253(n=2, weekday=6, starting_month=7, variation="last"), "Easter": Easter(), "Hour": Hour(1), "Minute": Minute(1), diff --git a/pandas/tests/resample/test_period_index.py b/pandas/tests/resample/test_period_index.py index dd058ada60974..d162a2c6e9f6a 100644 --- a/pandas/tests/resample/test_period_index.py +++ b/pandas/tests/resample/test_period_index.py @@ -164,7 +164,7 @@ def test_basic_downsample(self, simple_period_range_series): "rule,expected_error_msg", [ ("Y-DEC", ""), - ("Q-MAR", ""), + ("Q-MAR", ""), ("M", ""), ("w-thu", ""), ], diff --git a/pandas/tests/scalar/period/test_arithmetic.py b/pandas/tests/scalar/period/test_arithmetic.py index 97e486f9af060..ec04183dcf94e 100644 --- a/pandas/tests/scalar/period/test_arithmetic.py +++ b/pandas/tests/scalar/period/test_arithmetic.py @@ -99,7 +99,7 @@ def test_sub_n_gt_1_ticks(self, tick_classes, n): "offset, kwd_name", [ (offsets.YearEnd, "month"), - (offsets.QuarterEnd, "startingMonth"), + (offsets.QuarterEnd, "starting_month"), (offsets.MonthEnd, None), (offsets.Week, "weekday"), ], diff --git a/pandas/tests/scalar/period/test_period.py b/pandas/tests/scalar/period/test_period.py index 2c3a0816737fc..d318608bb60ad 100644 --- a/pandas/tests/scalar/period/test_period.py +++ b/pandas/tests/scalar/period/test_period.py @@ -35,7 +35,7 @@ class TestPeriodDisallowedFreqs: [ (offsets.BYearBegin(), "BYearBegin"), (offsets.YearBegin(2), "YearBegin"), - (offsets.QuarterBegin(startingMonth=12), "QuarterBegin"), + (offsets.QuarterBegin(starting_month=12), "QuarterBegin"), (offsets.BusinessMonthEnd(2), "BusinessMonthEnd"), ], ) @@ -259,10 +259,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(starting_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(starting_month=12) ) == Period(year=2005, quarter=2, freq="Q") assert Period(year=2005, month=3, day=1, freq=offsets.Day()) == Period( diff --git a/pandas/tests/tseries/offsets/test_business_quarter.py b/pandas/tests/tseries/offsets/test_business_quarter.py index ab3e55c4989fb..563f34cb1cb06 100644 --- a/pandas/tests/tseries/offsets/test_business_quarter.py +++ b/pandas/tests/tseries/offsets/test_business_quarter.py @@ -47,22 +47,22 @@ def test_on_offset(offset): class TestBQuarterBegin: 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(starting_month=3)) == expected + expected = "" + assert repr(BQuarterBegin(starting_month=1)) == expected def test_offset_corner_case(self): # corner - offset = BQuarterBegin(n=-1, startingMonth=1) + offset = BQuarterBegin(n=-1, starting_month=1) assert datetime(2007, 4, 3) + offset == datetime(2007, 4, 2) offset_cases = [] offset_cases.append( ( - BQuarterBegin(startingMonth=1), + BQuarterBegin(starting_month=1), { datetime(2008, 1, 1): datetime(2008, 4, 1), datetime(2008, 1, 31): datetime(2008, 4, 1), @@ -85,7 +85,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - BQuarterBegin(startingMonth=2), + BQuarterBegin(starting_month=2), { datetime(2008, 1, 1): datetime(2008, 2, 1), datetime(2008, 1, 31): datetime(2008, 2, 1), @@ -104,7 +104,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - BQuarterBegin(startingMonth=1, n=0), + BQuarterBegin(starting_month=1, n=0), { datetime(2008, 1, 1): datetime(2008, 1, 1), datetime(2007, 12, 31): datetime(2008, 1, 1), @@ -124,7 +124,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - BQuarterBegin(startingMonth=1, n=-1), + BQuarterBegin(starting_month=1, n=-1), { datetime(2008, 1, 1): datetime(2007, 10, 1), datetime(2008, 1, 31): datetime(2008, 1, 1), @@ -143,7 +143,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - BQuarterBegin(startingMonth=1, n=2), + BQuarterBegin(starting_month=1, n=2), { datetime(2008, 1, 1): datetime(2008, 7, 1), datetime(2008, 1, 15): datetime(2008, 7, 1), @@ -165,22 +165,22 @@ def test_offset(self, case): class TestBQuarterEnd: 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(starting_month=3)) == expected + expected = "" + assert repr(BQuarterEnd(starting_month=1)) == expected def test_offset_corner_case(self): # corner - offset = BQuarterEnd(n=-1, startingMonth=1) + offset = BQuarterEnd(n=-1, starting_month=1) assert datetime(2010, 1, 31) + offset == datetime(2010, 1, 29) offset_cases = [] offset_cases.append( ( - BQuarterEnd(startingMonth=1), + BQuarterEnd(starting_month=1), { datetime(2008, 1, 1): datetime(2008, 1, 31), datetime(2008, 1, 31): datetime(2008, 4, 30), @@ -196,7 +196,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - BQuarterEnd(startingMonth=2), + BQuarterEnd(starting_month=2), { datetime(2008, 1, 1): datetime(2008, 2, 29), datetime(2008, 1, 31): datetime(2008, 2, 29), @@ -212,7 +212,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - BQuarterEnd(startingMonth=1, n=0), + BQuarterEnd(starting_month=1, n=0), { datetime(2008, 1, 1): datetime(2008, 1, 31), datetime(2008, 1, 31): datetime(2008, 1, 31), @@ -228,7 +228,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - BQuarterEnd(startingMonth=1, n=-1), + BQuarterEnd(starting_month=1, n=-1), { datetime(2008, 1, 1): datetime(2007, 10, 31), datetime(2008, 1, 31): datetime(2007, 10, 31), @@ -244,7 +244,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - BQuarterEnd(startingMonth=1, n=2), + BQuarterEnd(starting_month=1, n=2), { datetime(2008, 1, 31): datetime(2008, 7, 31), datetime(2008, 2, 15): datetime(2008, 7, 31), @@ -264,33 +264,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, starting_month=1), datetime(2008, 1, 31), True), + (BQuarterEnd(1, starting_month=1), datetime(2007, 12, 31), False), + (BQuarterEnd(1, starting_month=1), datetime(2008, 2, 29), False), + (BQuarterEnd(1, starting_month=1), datetime(2007, 3, 30), False), + (BQuarterEnd(1, starting_month=1), datetime(2007, 3, 31), False), + (BQuarterEnd(1, starting_month=1), datetime(2008, 4, 30), True), + (BQuarterEnd(1, starting_month=1), datetime(2008, 5, 30), False), + (BQuarterEnd(1, starting_month=1), datetime(2007, 6, 29), False), + (BQuarterEnd(1, starting_month=1), datetime(2007, 6, 30), False), + (BQuarterEnd(1, starting_month=2), datetime(2008, 1, 31), False), + (BQuarterEnd(1, starting_month=2), datetime(2007, 12, 31), False), + (BQuarterEnd(1, starting_month=2), datetime(2008, 2, 29), True), + (BQuarterEnd(1, starting_month=2), datetime(2007, 3, 30), False), + (BQuarterEnd(1, starting_month=2), datetime(2007, 3, 31), False), + (BQuarterEnd(1, starting_month=2), datetime(2008, 4, 30), False), + (BQuarterEnd(1, starting_month=2), datetime(2008, 5, 30), True), + (BQuarterEnd(1, starting_month=2), datetime(2007, 6, 29), False), + (BQuarterEnd(1, starting_month=2), datetime(2007, 6, 30), False), + (BQuarterEnd(1, starting_month=3), datetime(2008, 1, 31), False), + (BQuarterEnd(1, starting_month=3), datetime(2007, 12, 31), True), + (BQuarterEnd(1, starting_month=3), datetime(2008, 2, 29), False), + (BQuarterEnd(1, starting_month=3), datetime(2007, 3, 30), True), + (BQuarterEnd(1, starting_month=3), datetime(2007, 3, 31), False), + (BQuarterEnd(1, starting_month=3), datetime(2008, 4, 30), False), + (BQuarterEnd(1, starting_month=3), datetime(2008, 5, 30), False), + (BQuarterEnd(1, starting_month=3), datetime(2007, 6, 29), True), + (BQuarterEnd(1, starting_month=3), datetime(2007, 6, 30), False), ] @pytest.mark.parametrize("case", on_offset_cases) diff --git a/pandas/tests/tseries/offsets/test_common.py b/pandas/tests/tseries/offsets/test_common.py index 3792878973c15..720c6c2071e7a 100644 --- a/pandas/tests/tseries/offsets/test_common.py +++ b/pandas/tests/tseries/offsets/test_common.py @@ -46,7 +46,7 @@ def _get_offset(klass, value=1, normalize=False): if klass is FY5253: klass = klass( n=value, - startingMonth=1, + starting_month=1, weekday=1, variation="last", normalize=normalize, @@ -54,7 +54,7 @@ def _get_offset(klass, value=1, normalize=False): elif klass is FY5253Quarter: klass = klass( n=value, - startingMonth=1, + starting_month=1, weekday=1, qtr_with_extra_week=1, variation="last", diff --git a/pandas/tests/tseries/offsets/test_fiscal.py b/pandas/tests/tseries/offsets/test_fiscal.py index f442b363f737d..fba15edc540a5 100644 --- a/pandas/tests/tseries/offsets/test_fiscal.py +++ b/pandas/tests/tseries/offsets/test_fiscal.py @@ -39,21 +39,21 @@ def makeFY5253LastOfMonth(*args, **kwds): def test_get_offset_name(): assert ( makeFY5253LastOfMonthQuarter( - weekday=1, startingMonth=3, qtr_with_extra_week=4 + weekday=1, starting_month=3, qtr_with_extra_week=4 ).freqstr == "REQ-L-MAR-TUE-4" ) assert ( makeFY5253NearestEndMonthQuarter( - weekday=1, startingMonth=3, qtr_with_extra_week=3 + weekday=1, starting_month=3, qtr_with_extra_week=3 ).freqstr == "REQ-N-MAR-TUE-3" ) class TestFY5253LastOfMonth: - offset_lom_sat_aug = makeFY5253LastOfMonth(1, startingMonth=8, weekday=WeekDay.SAT) - offset_lom_sat_sep = makeFY5253LastOfMonth(1, startingMonth=9, weekday=WeekDay.SAT) + offset_lom_sat_aug = makeFY5253LastOfMonth(1, starting_month=8, weekday=WeekDay.SAT) + offset_lom_sat_sep = makeFY5253LastOfMonth(1, starting_month=9, weekday=WeekDay.SAT) on_offset_cases = [ # From Wikipedia (see: @@ -99,9 +99,11 @@ def test_is_on_offset(self, case): assert_is_on_offset(offset, dt, expected) def test_apply(self): - offset_lom_aug_sat = makeFY5253LastOfMonth(startingMonth=8, weekday=WeekDay.SAT) + offset_lom_aug_sat = makeFY5253LastOfMonth( + starting_month=8, weekday=WeekDay.SAT + ) offset_lom_aug_sat_1 = makeFY5253LastOfMonth( - n=1, startingMonth=8, weekday=WeekDay.SAT + n=1, starting_month=8, weekday=WeekDay.SAT ) date_seq_lom_aug_sat = [ @@ -124,7 +126,7 @@ def test_apply(self): (offset_lom_aug_sat, [datetime(2006, 8, 25)] + date_seq_lom_aug_sat), (offset_lom_aug_sat_1, [datetime(2006, 8, 27)] + date_seq_lom_aug_sat[1:]), ( - makeFY5253LastOfMonth(n=-1, startingMonth=8, weekday=WeekDay.SAT), + makeFY5253LastOfMonth(n=-1, starting_month=8, weekday=WeekDay.SAT), list(reversed(date_seq_lom_aug_sat)), ), ] @@ -139,16 +141,16 @@ def test_apply(self): class TestFY5253NearestEndMonth: def test_get_year_end(self): assert makeFY5253NearestEndMonth( - startingMonth=8, weekday=WeekDay.SAT + starting_month=8, weekday=WeekDay.SAT ).get_year_end(datetime(2013, 1, 1)) == datetime(2013, 8, 31) assert makeFY5253NearestEndMonth( - startingMonth=8, weekday=WeekDay.SUN + starting_month=8, weekday=WeekDay.SUN ).get_year_end(datetime(2013, 1, 1)) == datetime(2013, 9, 1) assert makeFY5253NearestEndMonth( - startingMonth=8, weekday=WeekDay.FRI + starting_month=8, weekday=WeekDay.FRI ).get_year_end(datetime(2013, 1, 1)) == datetime(2013, 8, 30) - offset_n = FY5253(weekday=WeekDay.TUE, startingMonth=12, variation="nearest") + offset_n = FY5253(weekday=WeekDay.TUE, starting_month=12, variation="nearest") assert offset_n.get_year_end(datetime(2012, 1, 1)) == datetime(2013, 1, 1) assert offset_n.get_year_end(datetime(2012, 1, 10)) == datetime(2013, 1, 1) @@ -157,16 +159,16 @@ def test_get_year_end(self): assert offset_n.get_year_end(datetime(2013, 1, 3)) == datetime(2013, 12, 31) assert offset_n.get_year_end(datetime(2013, 1, 10)) == datetime(2013, 12, 31) - JNJ = FY5253(n=1, startingMonth=12, weekday=6, variation="nearest") + JNJ = FY5253(n=1, starting_month=12, weekday=6, variation="nearest") assert JNJ.get_year_end(datetime(2006, 1, 1)) == datetime(2006, 12, 31) offset_lom_aug_sat = makeFY5253NearestEndMonth( - 1, startingMonth=8, weekday=WeekDay.SAT + 1, starting_month=8, weekday=WeekDay.SAT ) offset_lom_aug_thu = makeFY5253NearestEndMonth( - 1, startingMonth=8, weekday=WeekDay.THU + 1, starting_month=8, weekday=WeekDay.THU ) - offset_n = FY5253(weekday=WeekDay.TUE, startingMonth=12, variation="nearest") + offset_n = FY5253(weekday=WeekDay.TUE, starting_month=12, variation="nearest") on_offset_cases = [ # From Wikipedia (see: @@ -245,43 +247,43 @@ def test_apply(self): datetime(2012, 12, 30), ] - DEC_SAT = FY5253(n=-1, startingMonth=12, weekday=5, variation="nearest") + DEC_SAT = FY5253(n=-1, starting_month=12, weekday=5, variation="nearest") tests = [ ( - makeFY5253NearestEndMonth(startingMonth=8, weekday=WeekDay.SAT), + makeFY5253NearestEndMonth(starting_month=8, weekday=WeekDay.SAT), date_seq_nem_8_sat, ), ( - makeFY5253NearestEndMonth(n=1, startingMonth=8, weekday=WeekDay.SAT), + makeFY5253NearestEndMonth(n=1, starting_month=8, weekday=WeekDay.SAT), date_seq_nem_8_sat, ), ( - makeFY5253NearestEndMonth(startingMonth=8, weekday=WeekDay.SAT), + makeFY5253NearestEndMonth(starting_month=8, weekday=WeekDay.SAT), [datetime(2006, 9, 1)] + date_seq_nem_8_sat, ), ( - makeFY5253NearestEndMonth(n=1, startingMonth=8, weekday=WeekDay.SAT), + makeFY5253NearestEndMonth(n=1, starting_month=8, weekday=WeekDay.SAT), [datetime(2006, 9, 3)] + date_seq_nem_8_sat[1:], ), ( - makeFY5253NearestEndMonth(n=-1, startingMonth=8, weekday=WeekDay.SAT), + makeFY5253NearestEndMonth(n=-1, starting_month=8, weekday=WeekDay.SAT), list(reversed(date_seq_nem_8_sat)), ), ( - makeFY5253NearestEndMonth(n=1, startingMonth=12, weekday=WeekDay.SUN), + makeFY5253NearestEndMonth(n=1, starting_month=12, weekday=WeekDay.SUN), JNJ, ), ( - makeFY5253NearestEndMonth(n=-1, startingMonth=12, weekday=WeekDay.SUN), + makeFY5253NearestEndMonth(n=-1, starting_month=12, weekday=WeekDay.SUN), list(reversed(JNJ)), ), ( - makeFY5253NearestEndMonth(n=1, startingMonth=12, weekday=WeekDay.SUN), + makeFY5253NearestEndMonth(n=1, starting_month=12, weekday=WeekDay.SUN), [datetime(2005, 1, 2), datetime(2006, 1, 1)], ), ( - makeFY5253NearestEndMonth(n=1, startingMonth=12, weekday=WeekDay.SUN), + makeFY5253NearestEndMonth(n=1, starting_month=12, weekday=WeekDay.SUN), [datetime(2006, 1, 2), datetime(2006, 12, 31)], ), (DEC_SAT, [datetime(2013, 1, 15), datetime(2012, 12, 29)]), @@ -297,37 +299,37 @@ def test_apply(self): class TestFY5253LastOfMonthQuarter: def test_equality(self): assert makeFY5253LastOfMonthQuarter( - startingMonth=1, weekday=WeekDay.SAT, qtr_with_extra_week=4 + starting_month=1, weekday=WeekDay.SAT, qtr_with_extra_week=4 ) == makeFY5253LastOfMonthQuarter( - startingMonth=1, weekday=WeekDay.SAT, qtr_with_extra_week=4 + starting_month=1, weekday=WeekDay.SAT, qtr_with_extra_week=4 ) assert makeFY5253LastOfMonthQuarter( - startingMonth=1, weekday=WeekDay.SAT, qtr_with_extra_week=4 + starting_month=1, weekday=WeekDay.SAT, qtr_with_extra_week=4 ) != makeFY5253LastOfMonthQuarter( - startingMonth=1, weekday=WeekDay.SUN, qtr_with_extra_week=4 + starting_month=1, weekday=WeekDay.SUN, qtr_with_extra_week=4 ) assert makeFY5253LastOfMonthQuarter( - startingMonth=1, weekday=WeekDay.SAT, qtr_with_extra_week=4 + starting_month=1, weekday=WeekDay.SAT, qtr_with_extra_week=4 ) != makeFY5253LastOfMonthQuarter( - startingMonth=2, weekday=WeekDay.SAT, qtr_with_extra_week=4 + starting_month=2, weekday=WeekDay.SAT, qtr_with_extra_week=4 ) def test_offset(self): offset = makeFY5253LastOfMonthQuarter( - 1, startingMonth=9, weekday=WeekDay.SAT, qtr_with_extra_week=4 + 1, starting_month=9, weekday=WeekDay.SAT, qtr_with_extra_week=4 ) offset2 = makeFY5253LastOfMonthQuarter( - 2, startingMonth=9, weekday=WeekDay.SAT, qtr_with_extra_week=4 + 2, starting_month=9, weekday=WeekDay.SAT, qtr_with_extra_week=4 ) offset4 = makeFY5253LastOfMonthQuarter( - 4, startingMonth=9, weekday=WeekDay.SAT, qtr_with_extra_week=4 + 4, starting_month=9, weekday=WeekDay.SAT, qtr_with_extra_week=4 ) offset_neg1 = makeFY5253LastOfMonthQuarter( - -1, startingMonth=9, weekday=WeekDay.SAT, qtr_with_extra_week=4 + -1, starting_month=9, weekday=WeekDay.SAT, qtr_with_extra_week=4 ) offset_neg2 = makeFY5253LastOfMonthQuarter( - -2, startingMonth=9, weekday=WeekDay.SAT, qtr_with_extra_week=4 + -2, starting_month=9, weekday=WeekDay.SAT, qtr_with_extra_week=4 ) GMCR = [ @@ -373,10 +375,10 @@ def test_offset(self): date = date + offset_neg1 lomq_aug_sat_4 = makeFY5253LastOfMonthQuarter( - 1, startingMonth=8, weekday=WeekDay.SAT, qtr_with_extra_week=4 + 1, starting_month=8, weekday=WeekDay.SAT, qtr_with_extra_week=4 ) lomq_sep_sat_4 = makeFY5253LastOfMonthQuarter( - 1, startingMonth=9, weekday=WeekDay.SAT, qtr_with_extra_week=4 + 1, starting_month=9, weekday=WeekDay.SAT, qtr_with_extra_week=4 ) on_offset_cases = [ @@ -416,7 +418,7 @@ def test_offset(self): # See: http://www.intc.com/releasedetail.cfm?ReleaseID=542844 ( makeFY5253LastOfMonthQuarter( - 1, startingMonth=12, weekday=WeekDay.SAT, qtr_with_extra_week=1 + 1, starting_month=12, weekday=WeekDay.SAT, qtr_with_extra_week=1 ), datetime(2011, 4, 2), True, @@ -424,21 +426,21 @@ def test_offset(self): # see: http://google.brand.edgar-online.com/?sym=INTC&formtypeID=7 ( makeFY5253LastOfMonthQuarter( - 1, startingMonth=12, weekday=WeekDay.SAT, qtr_with_extra_week=1 + 1, starting_month=12, weekday=WeekDay.SAT, qtr_with_extra_week=1 ), datetime(2012, 12, 29), True, ), ( makeFY5253LastOfMonthQuarter( - 1, startingMonth=12, weekday=WeekDay.SAT, qtr_with_extra_week=1 + 1, starting_month=12, weekday=WeekDay.SAT, qtr_with_extra_week=1 ), datetime(2011, 12, 31), True, ), ( makeFY5253LastOfMonthQuarter( - 1, startingMonth=12, weekday=WeekDay.SAT, qtr_with_extra_week=1 + 1, starting_month=12, weekday=WeekDay.SAT, qtr_with_extra_week=1 ), datetime(2010, 12, 25), True, @@ -453,45 +455,45 @@ def test_is_on_offset(self, case): def test_year_has_extra_week(self): # End of long Q1 assert makeFY5253LastOfMonthQuarter( - 1, startingMonth=12, weekday=WeekDay.SAT, qtr_with_extra_week=1 + 1, starting_month=12, weekday=WeekDay.SAT, qtr_with_extra_week=1 ).year_has_extra_week(datetime(2011, 4, 2)) # Start of long Q1 assert makeFY5253LastOfMonthQuarter( - 1, startingMonth=12, weekday=WeekDay.SAT, qtr_with_extra_week=1 + 1, starting_month=12, weekday=WeekDay.SAT, qtr_with_extra_week=1 ).year_has_extra_week(datetime(2010, 12, 26)) # End of year before year with long Q1 assert not makeFY5253LastOfMonthQuarter( - 1, startingMonth=12, weekday=WeekDay.SAT, qtr_with_extra_week=1 + 1, starting_month=12, weekday=WeekDay.SAT, qtr_with_extra_week=1 ).year_has_extra_week(datetime(2010, 12, 25)) for year in [ x for x in range(1994, 2011 + 1) if x not in [2011, 2005, 2000, 1994] ]: assert not makeFY5253LastOfMonthQuarter( - 1, startingMonth=12, weekday=WeekDay.SAT, qtr_with_extra_week=1 + 1, starting_month=12, weekday=WeekDay.SAT, qtr_with_extra_week=1 ).year_has_extra_week(datetime(year, 4, 2)) # Other long years assert makeFY5253LastOfMonthQuarter( - 1, startingMonth=12, weekday=WeekDay.SAT, qtr_with_extra_week=1 + 1, starting_month=12, weekday=WeekDay.SAT, qtr_with_extra_week=1 ).year_has_extra_week(datetime(2005, 4, 2)) assert makeFY5253LastOfMonthQuarter( - 1, startingMonth=12, weekday=WeekDay.SAT, qtr_with_extra_week=1 + 1, starting_month=12, weekday=WeekDay.SAT, qtr_with_extra_week=1 ).year_has_extra_week(datetime(2000, 4, 2)) assert makeFY5253LastOfMonthQuarter( - 1, startingMonth=12, weekday=WeekDay.SAT, qtr_with_extra_week=1 + 1, starting_month=12, weekday=WeekDay.SAT, qtr_with_extra_week=1 ).year_has_extra_week(datetime(1994, 4, 2)) def test_get_weeks(self): sat_dec_1 = makeFY5253LastOfMonthQuarter( - 1, startingMonth=12, weekday=WeekDay.SAT, qtr_with_extra_week=1 + 1, starting_month=12, weekday=WeekDay.SAT, qtr_with_extra_week=1 ) sat_dec_4 = makeFY5253LastOfMonthQuarter( - 1, startingMonth=12, weekday=WeekDay.SAT, qtr_with_extra_week=4 + 1, starting_month=12, weekday=WeekDay.SAT, qtr_with_extra_week=4 ) assert sat_dec_1.get_weeks(datetime(2011, 4, 2)) == [14, 13, 13, 13] @@ -501,12 +503,12 @@ def test_get_weeks(self): class TestFY5253NearestEndMonthQuarter: offset_nem_sat_aug_4 = makeFY5253NearestEndMonthQuarter( - 1, startingMonth=8, weekday=WeekDay.SAT, qtr_with_extra_week=4 + 1, starting_month=8, weekday=WeekDay.SAT, qtr_with_extra_week=4 ) offset_nem_thu_aug_4 = makeFY5253NearestEndMonthQuarter( - 1, startingMonth=8, weekday=WeekDay.THU, qtr_with_extra_week=4 + 1, starting_month=8, weekday=WeekDay.THU, qtr_with_extra_week=4 ) - offset_n = FY5253(weekday=WeekDay.TUE, startingMonth=12, variation="nearest") + offset_n = FY5253(weekday=WeekDay.TUE, starting_month=12, variation="nearest") on_offset_cases = [ # From Wikipedia @@ -556,7 +558,7 @@ def test_is_on_offset(self, case): def test_offset(self): offset = makeFY5253NearestEndMonthQuarter( - 1, startingMonth=8, weekday=WeekDay.THU, qtr_with_extra_week=4 + 1, starting_month=8, weekday=WeekDay.THU, qtr_with_extra_week=4 ) MU = [ @@ -576,7 +578,7 @@ def test_offset(self): assert_offset_equal(offset, datetime(2012, 5, 30), datetime(2012, 5, 31)) offset2 = FY5253Quarter( - weekday=5, startingMonth=12, variation="last", qtr_with_extra_week=4 + weekday=5, starting_month=12, variation="last", qtr_with_extra_week=4 ) assert_offset_equal(offset2, datetime(2013, 1, 15), datetime(2013, 3, 30)) @@ -584,7 +586,7 @@ def test_offset(self): def test_bunched_yearends(): # GH#14774 cases with two fiscal year-ends in the same calendar-year - fy = FY5253(n=1, weekday=5, startingMonth=12, variation="nearest") + fy = FY5253(n=1, weekday=5, starting_month=12, variation="nearest") dt = Timestamp("2004-01-01") assert fy.rollback(dt) == Timestamp("2002-12-28") assert (-fy)._apply(dt) == Timestamp("2002-12-28") @@ -604,7 +606,7 @@ def test_bunched_yearends(): def test_fy5253_last_onoffset(): # GH#18877 dates on the year-end but not normalized to midnight - offset = FY5253(n=-5, startingMonth=5, variation="last", weekday=0) + offset = FY5253(n=-5, starting_month=5, variation="last", weekday=0) ts = Timestamp("1984-05-28 06:29:43.955911354+0200", tz="Europe/San_Marino") fast = offset.is_on_offset(ts) slow = (ts + offset) - offset == ts @@ -613,7 +615,7 @@ def test_fy5253_last_onoffset(): def test_fy5253_nearest_onoffset(): # GH#18877 dates on the year-end but not normalized to midnight - offset = FY5253(n=3, startingMonth=7, variation="nearest", weekday=2) + offset = FY5253(n=3, starting_month=7, variation="nearest", weekday=2) ts = Timestamp("2032-07-28 00:12:59.035729419+0000", tz="Africa/Dakar") fast = offset.is_on_offset(ts) slow = (ts + offset) - offset == ts @@ -624,7 +626,7 @@ def test_fy5253qtr_onoffset_nearest(): # GH#19036 ts = Timestamp("1985-09-02 23:57:46.232550356-0300", tz="Atlantic/Bermuda") offset = FY5253Quarter( - n=3, qtr_with_extra_week=1, startingMonth=2, variation="nearest", weekday=0 + n=3, qtr_with_extra_week=1, starting_month=2, variation="nearest", weekday=0 ) fast = offset.is_on_offset(ts) slow = (ts + offset) - offset == ts @@ -634,7 +636,7 @@ def test_fy5253qtr_onoffset_nearest(): def test_fy5253qtr_onoffset_last(): # GH#19036 offset = FY5253Quarter( - n=-2, qtr_with_extra_week=1, startingMonth=7, variation="last", weekday=2 + n=-2, qtr_with_extra_week=1, starting_month=7, variation="last", weekday=2 ) ts = Timestamp("2011-01-26 19:03:40.331096129+0200", tz="Africa/Windhoek") slow = (ts + offset) - offset == ts diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index 1e5bfa6033216..b6a81d3d87c10 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -75,7 +75,7 @@ def _create_offset(klass, value=1, normalize=False): if klass is FY5253: klass = klass( n=value, - startingMonth=1, + starting_month=1, weekday=1, variation="last", normalize=normalize, @@ -83,7 +83,7 @@ def _create_offset(klass, value=1, normalize=False): elif klass is FY5253Quarter: klass = klass( n=value, - startingMonth=1, + starting_month=1, weekday=1, qtr_with_extra_week=1, variation="last", diff --git a/pandas/tests/tseries/offsets/test_quarter.py b/pandas/tests/tseries/offsets/test_quarter.py index b92ff9d39a3ca..62828ee734993 100644 --- a/pandas/tests/tseries/offsets/test_quarter.py +++ b/pandas/tests/tseries/offsets/test_quarter.py @@ -46,22 +46,22 @@ def test_on_offset(offset, date): class TestQuarterBegin: 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(starting_month=3)) == expected + expected = "" + assert repr(QuarterBegin(starting_month=1)) == expected def test_offset_corner_case(self): # corner - offset = QuarterBegin(n=-1, startingMonth=1) + offset = QuarterBegin(n=-1, starting_month=1) assert datetime(2010, 2, 1) + offset == datetime(2010, 1, 1) offset_cases = [] offset_cases.append( ( - QuarterBegin(startingMonth=1), + QuarterBegin(starting_month=1), { datetime(2007, 12, 1): datetime(2008, 1, 1), datetime(2008, 1, 1): datetime(2008, 4, 1), @@ -77,7 +77,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - QuarterBegin(startingMonth=2), + QuarterBegin(starting_month=2), { datetime(2008, 1, 1): datetime(2008, 2, 1), datetime(2008, 1, 31): datetime(2008, 2, 1), @@ -93,7 +93,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - QuarterBegin(startingMonth=1, n=0), + QuarterBegin(starting_month=1, n=0), { datetime(2008, 1, 1): datetime(2008, 1, 1), datetime(2008, 12, 1): datetime(2009, 1, 1), @@ -110,7 +110,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - QuarterBegin(startingMonth=1, n=-1), + QuarterBegin(starting_month=1, n=-1), { datetime(2008, 1, 1): datetime(2007, 10, 1), datetime(2008, 1, 31): datetime(2008, 1, 1), @@ -127,7 +127,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - QuarterBegin(startingMonth=1, n=2), + QuarterBegin(starting_month=1, n=2), { datetime(2008, 1, 1): datetime(2008, 7, 1), datetime(2008, 2, 15): datetime(2008, 7, 1), @@ -149,22 +149,22 @@ def test_offset(self, case): class TestQuarterEnd: 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(starting_month=3)) == expected + expected = "" + assert repr(QuarterEnd(starting_month=1)) == expected def test_offset_corner_case(self): # corner - offset = QuarterEnd(n=-1, startingMonth=1) + offset = QuarterEnd(n=-1, starting_month=1) assert datetime(2010, 2, 1) + offset == datetime(2010, 1, 31) offset_cases = [] offset_cases.append( ( - QuarterEnd(startingMonth=1), + QuarterEnd(starting_month=1), { datetime(2008, 1, 1): datetime(2008, 1, 31), datetime(2008, 1, 31): datetime(2008, 4, 30), @@ -180,7 +180,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - QuarterEnd(startingMonth=2), + QuarterEnd(starting_month=2), { datetime(2008, 1, 1): datetime(2008, 2, 29), datetime(2008, 1, 31): datetime(2008, 2, 29), @@ -196,7 +196,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - QuarterEnd(startingMonth=1, n=0), + QuarterEnd(starting_month=1, n=0), { datetime(2008, 1, 1): datetime(2008, 1, 31), datetime(2008, 1, 31): datetime(2008, 1, 31), @@ -212,7 +212,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - QuarterEnd(startingMonth=1, n=-1), + QuarterEnd(starting_month=1, n=-1), { datetime(2008, 1, 1): datetime(2007, 10, 31), datetime(2008, 1, 31): datetime(2007, 10, 31), @@ -229,7 +229,7 @@ def test_offset_corner_case(self): offset_cases.append( ( - QuarterEnd(startingMonth=1, n=2), + QuarterEnd(starting_month=1, n=2), { datetime(2008, 1, 31): datetime(2008, 7, 31), datetime(2008, 2, 15): datetime(2008, 7, 31), @@ -249,36 +249,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, starting_month=1), datetime(2008, 1, 31), True), + (QuarterEnd(1, starting_month=1), datetime(2007, 12, 31), False), + (QuarterEnd(1, starting_month=1), datetime(2008, 2, 29), False), + (QuarterEnd(1, starting_month=1), datetime(2007, 3, 30), False), + (QuarterEnd(1, starting_month=1), datetime(2007, 3, 31), False), + (QuarterEnd(1, starting_month=1), datetime(2008, 4, 30), True), + (QuarterEnd(1, starting_month=1), datetime(2008, 5, 30), False), + (QuarterEnd(1, starting_month=1), datetime(2008, 5, 31), False), + (QuarterEnd(1, starting_month=1), datetime(2007, 6, 29), False), + (QuarterEnd(1, starting_month=1), datetime(2007, 6, 30), False), + (QuarterEnd(1, starting_month=2), datetime(2008, 1, 31), False), + (QuarterEnd(1, starting_month=2), datetime(2007, 12, 31), False), + (QuarterEnd(1, starting_month=2), datetime(2008, 2, 29), True), + (QuarterEnd(1, starting_month=2), datetime(2007, 3, 30), False), + (QuarterEnd(1, starting_month=2), datetime(2007, 3, 31), False), + (QuarterEnd(1, starting_month=2), datetime(2008, 4, 30), False), + (QuarterEnd(1, starting_month=2), datetime(2008, 5, 30), False), + (QuarterEnd(1, starting_month=2), datetime(2008, 5, 31), True), + (QuarterEnd(1, starting_month=2), datetime(2007, 6, 29), False), + (QuarterEnd(1, starting_month=2), datetime(2007, 6, 30), False), + (QuarterEnd(1, starting_month=3), datetime(2008, 1, 31), False), + (QuarterEnd(1, starting_month=3), datetime(2007, 12, 31), True), + (QuarterEnd(1, starting_month=3), datetime(2008, 2, 29), False), + (QuarterEnd(1, starting_month=3), datetime(2007, 3, 30), False), + (QuarterEnd(1, starting_month=3), datetime(2007, 3, 31), True), + (QuarterEnd(1, starting_month=3), datetime(2008, 4, 30), False), + (QuarterEnd(1, starting_month=3), datetime(2008, 5, 30), False), + (QuarterEnd(1, starting_month=3), datetime(2008, 5, 31), False), + (QuarterEnd(1, starting_month=3), datetime(2007, 6, 29), False), + (QuarterEnd(1, starting_month=3), datetime(2007, 6, 30), True), ] @pytest.mark.parametrize("case", on_offset_cases) diff --git a/pandas/tests/tslibs/test_libfrequencies.py b/pandas/tests/tslibs/test_libfrequencies.py index effd3b4b8b4e5..21cdb81e9467a 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(starting_month=12).freqstr, "DEC"), ("Q-JAN", "JAN"), - (offsets.QuarterEnd(startingMonth=1).freqstr, "JAN"), + (offsets.QuarterEnd(starting_month=1).freqstr, "JAN"), ("Y-DEC", "DEC"), (offsets.YearEnd().freqstr, "DEC"), ("Y-MAY", "MAY"), From 69e3a5adfaf1c2171b1a4ffd4abb2927e4cfef20 Mon Sep 17 00:00:00 2001 From: gboeker Date: Wed, 3 Apr 2024 13:09:29 -0400 Subject: [PATCH 4/6] change startingMonth in test files --- 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 ad4e9e2bcf38a..cb074abcf1ba9 100644 --- a/pandas/tests/tslibs/test_to_offset.py +++ b/pandas/tests/tslibs/test_to_offset.py @@ -160,9 +160,9 @@ def test_to_offset_pd_timedelta(kwargs, expected): [ ("W", offsets.Week(weekday=6)), ("W-SUN", offsets.Week(weekday=6)), - ("QE", offsets.QuarterEnd(startingMonth=12)), - ("QE-DEC", offsets.QuarterEnd(startingMonth=12)), - ("QE-MAY", offsets.QuarterEnd(startingMonth=5)), + ("QE", offsets.QuarterEnd(starting_month=12)), + ("QE-DEC", offsets.QuarterEnd(starting_month=12)), + ("QE-MAY", offsets.QuarterEnd(starting_month=5)), ("SME", offsets.SemiMonthEnd(day_of_month=15)), ("SME-15", offsets.SemiMonthEnd(day_of_month=15)), ("SME-1", offsets.SemiMonthEnd(day_of_month=1)), From 9df38e722a6776b8c48c2348e2a89e868e215212 Mon Sep 17 00:00:00 2001 From: gboeker Date: Sat, 4 May 2024 11:17:28 -0400 Subject: [PATCH 5/6] fix line too long --- pandas/_libs/tslibs/offsets.pyx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 9321bc4ebaa0a..8829e99e11f4b 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2843,7 +2843,15 @@ cdef class QuarterEnd(QuarterOffset): cdef readonly: int _period_dtype_code - def __init__(self, n=1, normalize=False, starting_month=None): + def __init__(self, n=1, normalize=False, startingMonth=None, + *, starting_month=None): + if startingMonth is not None: + warnings.warn( + "`startingMonth` is deprecated and will be removed in a future " + "version. Use `starting_month` instead", + DeprecationWarning + ) + starting_month = startingMonth # Because QuarterEnd can be the freq for a Period, define its # _period_dtype_code at construction for performance QuarterOffset.__init__(self, n, normalize, starting_month) From 1c6acf04baafb602e6dc1fd5c6ae5028919d4f4b Mon Sep 17 00:00:00 2001 From: gboeker Date: Mon, 6 May 2024 12:12:09 -0400 Subject: [PATCH 6/6] fix correct function --- pandas/_libs/tslibs/offsets.pyx | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 8829e99e11f4b..cbe29b7b21a40 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -2667,7 +2667,16 @@ cdef class QuarterOffset(SingleConstructorOffset): cdef readonly: int starting_month - def __init__(self, n=1, normalize=False, starting_month=None): + def __init__(self, n=1, normalize=False, startingMonth=None, + *, starting_month=None): + if startingMonth is not None: + warnings.warn( + "`startingMonth` is deprecated and will be removed in a future " + "version. Use `starting_month` instead", + DeprecationWarning + ) + starting_month = startingMonth + BaseOffset.__init__(self, n, normalize) if starting_month is None: @@ -2843,15 +2852,7 @@ cdef class QuarterEnd(QuarterOffset): cdef readonly: int _period_dtype_code - def __init__(self, n=1, normalize=False, startingMonth=None, - *, starting_month=None): - if startingMonth is not None: - warnings.warn( - "`startingMonth` is deprecated and will be removed in a future " - "version. Use `starting_month` instead", - DeprecationWarning - ) - starting_month = startingMonth + def __init__(self, n=1, normalize=False, starting_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, starting_month)