Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: DatetimeIndex.is_year_start and DatetimeIndex.is_quarter_start always return False on double-digit frequencies #58549

3 changes: 2 additions & 1 deletion pandas/_libs/tslibs/fields.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ def get_start_end_field(
# month of year. Other offsets use month, startingMonth as ending
# month of year.

if freqstr[0:2] in ["MS", "QS", "YS"]:
freq_name = freqstr.lstrip("B")[0:2]
if freq_name in ["MS", "QS", "YS"]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry i meant that the argument freqstr in get_start_end_field needs renaming, because you're no longer passing in freq.freqstr but freq.name, so function argument (line 213) needs renaming

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, it's clear now. I renamed the argument freqstr in get_start_end_field

end_month = 12 if month_kw == 1 else month_kw - 1
start_month = month_kw
else:
Expand Down
5 changes: 2 additions & 3 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -579,16 +579,15 @@ cdef class _Timestamp(ABCTimestamp):
if freq:
kwds = freq.kwds
month_kw = kwds.get("startingMonth", kwds.get("month", 12))
freqstr = freq.freqstr
freqstr = to_offset(freq.freqstr).name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it work to directly do freq.name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, it works with freq.name indeed. I simplified to_offset(freq.freqstr).name

else:
month_kw = 12
freqstr = None

val = self._maybe_convert_value_to_local()

out = get_start_end_field(np.array([val], dtype=np.int64),
field, to_offset(freqstr).name ,
month_kw, self._creso)
field, freqstr, month_kw, self._creso)
return out[0]

@property
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ def f(self):
kwds = freq.kwds
month_kw = kwds.get("startingMonth", kwds.get("month", 12))

if self.freqstr is not None:
freqstr = to_offset(self.freqstr).name
if freq is not None:
freqstr = to_offset(freq.freqstr).name
else:
freqstr = self.freqstr
freqstr = freq
result = fields.get_start_end_field(
values, field, freqstr, month_kw, reso=self._creso
)
Expand Down