Skip to content

Commit

Permalink
BUG: DatetimeIndex.is_year_start breaks on custom business days frequ…
Browse files Browse the repository at this point in the history
…encies bigger then `1C` (#58665)

* fix bug dti.is_year_start breaks on freq custom business day with digit

* rename the variable freqstr

* delete double space
  • Loading branch information
natmokval committed May 11, 2024
1 parent 56b6c8a commit 34177d6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion doc/source/whatsnew/v3.0.0.rst
Expand Up @@ -384,6 +384,8 @@ Datetimelike
- Bug in :func:`date_range` where the last valid timestamp would sometimes not be produced (:issue:`56134`)
- Bug in :func:`date_range` where using a negative frequency value would not include all points between the start and end values (:issue:`56382`)
- Bug in :func:`tseries.api.guess_datetime_format` would fail to infer time format when "%Y" == "%H%M" (:issue:`57452`)
- Bug in :meth:`DatetimeIndex.is_year_start` and :meth:`DatetimeIndex.is_quarter_start` does not raise on Custom business days frequencies bigger then "1C" (:issue:`58664`)
- Bug in :meth:`DatetimeIndex.is_year_start` and :meth:`DatetimeIndex.is_quarter_start` returning ``False`` on double-digit frequencies (:issue:`58523`)
- Bug in setting scalar values with mismatched resolution into arrays with non-nanosecond ``datetime64``, ``timedelta64`` or :class:`DatetimeTZDtype` incorrectly truncating those scalars (:issue:`56410`)

Timedelta
Expand Down Expand Up @@ -421,7 +423,6 @@ Interval
Indexing
^^^^^^^^
- Bug in :meth:`DataFrame.__getitem__` returning modified columns when called with ``slice`` in Python 3.12 (:issue:`57500`)
- Bug in :meth:`DatetimeIndex.is_year_start` and :meth:`DatetimeIndex.is_quarter_start` returning ``False`` on double-digit frequencies (:issue:`58523`)
-

Missing
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/fields.pyx
Expand Up @@ -253,7 +253,7 @@ def get_start_end_field(
# month of year. Other offsets use month, startingMonth as ending
# month of year.

if freq_name.lstrip("B")[0:2] in ["MS", "QS", "YS"]:
if freq_name.lstrip("B")[0:2] in ["MS", "QS", "YS"]:
end_month = 12 if month_kw == 1 else month_kw - 1
start_month = month_kw
else:
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/indexes/datetimes/test_scalar_compat.py
Expand Up @@ -336,3 +336,10 @@ def test_dti_is_year_quarter_start_doubledigit_freq(self):

dr = date_range("2017-01-01", periods=2, freq="10QS")
assert all(dr.is_quarter_start)

def test_dti_is_year_start_freq_custom_business_day_with_digit(self):
# GH#58664
dr = date_range("2020-01-01", periods=2, freq="2C")
msg = "Custom business days is not supported by is_year_start"
with pytest.raises(ValueError, match=msg):
dr.is_year_start

0 comments on commit 34177d6

Please sign in to comment.