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: 1 addition & 2 deletions pandas/_libs/tslibs/fields.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ from pandas._libs.tslibs.np_datetime cimport (
pandas_timedelta_to_timedeltastruct,
pandas_timedeltastruct,
)
from pandas._libs.tslibs.offsets cimport to_offset

import_pandas_datetime()

Expand Down Expand Up @@ -254,7 +253,7 @@ def get_start_end_field(
# month of year. Other offsets use month, startingMonth as ending
# month of year.

if to_offset(freqstr).name[0:2] in ["MS", "QS", "YS"]:
if freqstr[0:2] 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.

we should also rename the variable name now if something else is being passed in (freq_name?)

end_month = 12 if month_kw == 1 else month_kw - 1
start_month = month_kw
else:
Expand Down
3 changes: 2 additions & 1 deletion pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,8 @@ cdef class _Timestamp(ABCTimestamp):
val = self._maybe_convert_value_to_local()

out = get_start_end_field(np.array([val], dtype=np.int64),
field, freqstr, month_kw, self._creso)
field, to_offset(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.

there's already freq a few lines above, can we just take it from there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry, I am not sure if I understand correctly. I replaced freqstr = freq.freqstr with freqstr = to_offset(freq.freqstr).name a few lines above.

month_kw, self._creso)
return out[0]

@property
Expand Down
6 changes: 5 additions & 1 deletion pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,12 @@ 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
else:
freqstr = self.freqstr
result = fields.get_start_end_field(
values, field, self.freqstr, month_kw, reso=self._creso
values, field, freqstr, month_kw, reso=self._creso
Copy link
Member

Choose a reason for hiding this comment

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

same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

)
else:
result = fields.get_date_field(values, field, reso=self._creso)
Expand Down