From 020f5a3dc9c5c64a18e0080f8574169d83348fd5 Mon Sep 17 00:00:00 2001 From: visweswaran1998 Date: Thu, 2 May 2024 22:54:18 +0530 Subject: [PATCH 1/3] BUG: DatetimeIndex.is_year_start breaks on double-digit frequencies #58523 --- pandas/_libs/tslibs/fields.pyx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pandas/_libs/tslibs/fields.pyx b/pandas/_libs/tslibs/fields.pyx index ff4fb4d635d17..0f5eb401f712a 100644 --- a/pandas/_libs/tslibs/fields.pyx +++ b/pandas/_libs/tslibs/fields.pyx @@ -252,9 +252,10 @@ def get_start_end_field( # QuarterBegin(), BQuarterBegin() use startingMonth = starting # month of year. Other offsets use month, startingMonth as ending # month of year. - - if (freqstr[0:2] in ["MS", "QS", "YS"]) or ( - freqstr[1:3] in ["MS", "QS", "YS"]): + period_str = "".join([ + dt_char for dt_char in list(freqstr.split("-")[0]) if not dt_char.isdigit() + ]) + if (period_str in ["MS", "QS", "YS"]): end_month = 12 if month_kw == 1 else month_kw - 1 start_month = month_kw else: From 8df36f7960f369654370b94079080e52e8c381d3 Mon Sep 17 00:00:00 2001 From: visweswaran1998 Date: Thu, 2 May 2024 23:36:22 +0530 Subject: [PATCH 2/3] May fix #58523 & #58524 --- pandas/_libs/tslibs/fields.pyx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pandas/_libs/tslibs/fields.pyx b/pandas/_libs/tslibs/fields.pyx index 0f5eb401f712a..61ea9bd558489 100644 --- a/pandas/_libs/tslibs/fields.pyx +++ b/pandas/_libs/tslibs/fields.pyx @@ -246,15 +246,14 @@ def get_start_end_field( if freqstr: if freqstr == "C": raise ValueError(f"Custom business days is not supported by {field}") - is_business = freqstr[0] == "B" - + period_str = "".join([ + dt_char for dt_char in list(freqstr.split("-")[0]) if not dt_char.isdigit() + ]) + is_business = period_str == "B" # YearBegin(), BYearBegin() use month = starting month of year. # QuarterBegin(), BQuarterBegin() use startingMonth = starting # month of year. Other offsets use month, startingMonth as ending # month of year. - period_str = "".join([ - dt_char for dt_char in list(freqstr.split("-")[0]) if not dt_char.isdigit() - ]) if (period_str in ["MS", "QS", "YS"]): end_month = 12 if month_kw == 1 else month_kw - 1 start_month = month_kw From 443724ed0170692eb03abdca445afe5f468c838e Mon Sep 17 00:00:00 2001 From: visweswaran1998 Date: Fri, 3 May 2024 23:08:40 +0530 Subject: [PATCH 3/3] Fixing the failed test case --- pandas/_libs/tslibs/fields.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/fields.pyx b/pandas/_libs/tslibs/fields.pyx index 61ea9bd558489..76a77cc8c606a 100644 --- a/pandas/_libs/tslibs/fields.pyx +++ b/pandas/_libs/tslibs/fields.pyx @@ -249,7 +249,7 @@ def get_start_end_field( period_str = "".join([ dt_char for dt_char in list(freqstr.split("-")[0]) if not dt_char.isdigit() ]) - is_business = period_str == "B" + is_business = period_str.startswith("B") # YearBegin(), BYearBegin() use month = starting month of year. # QuarterBegin(), BQuarterBegin() use startingMonth = starting # month of year. Other offsets use month, startingMonth as ending