Skip to content

Commit 37f3e22

Browse files
Revert "BUG: first("1M") returning two months when first day is last day of month (#38331)"
This reverts commit 6ecc787.
1 parent 36c4d5c commit 37f3e22

File tree

3 files changed

+2
-17
lines changed

3 files changed

+2
-17
lines changed

doc/source/whatsnew/v1.2.0.rst

-1
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,6 @@ Datetimelike
607607
- Bug in :meth:`Series.isin` with ``datetime64[ns]`` dtype and :meth:`.DatetimeIndex.isin` failing to consider timezone-aware and timezone-naive datetimes as always different (:issue:`35728`)
608608
- Bug in :meth:`Series.isin` with ``PeriodDtype`` dtype and :meth:`PeriodIndex.isin` failing to consider arguments with different ``PeriodDtype`` as always different (:issue:`37528`)
609609
- Bug in :class:`Period` constructor now correctly handles nanoseconds in the ``value`` argument (:issue:`34621` and :issue:`17053`)
610-
- Bug in :meth:`DataFrame.first` and :meth:`Series.first` returning two months for offset one month when first day is last calendar day (:issue:`29623`)
611610

612611
Timedelta
613612
^^^^^^^^^

pandas/core/generic.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -8420,11 +8420,7 @@ def first(self: FrameOrSeries, offset) -> FrameOrSeries:
84208420
return self
84218421

84228422
offset = to_offset(offset)
8423-
if not isinstance(offset, Tick) and offset.is_on_offset(self.index[0]):
8424-
# GH#29623 if first value is end of period
8425-
end_date = end = self.index[0]
8426-
else:
8427-
end_date = end = self.index[0] + offset
8423+
end_date = end = self.index[0] + offset
84288424

84298425
# Tick-like, e.g. 3 weeks
84308426
if isinstance(offset, Tick):

pandas/tests/frame/methods/test_first_and_last.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44
import pytest
55

6-
from pandas import DataFrame, bdate_range
6+
from pandas import DataFrame
77
import pandas._testing as tm
88

99

@@ -69,13 +69,3 @@ def test_last_subset(self, frame_or_series):
6969

7070
result = ts[:0].last("3M")
7171
tm.assert_equal(result, ts[:0])
72-
73-
@pytest.mark.parametrize("start, periods", [("2010-03-31", 1), ("2010-03-30", 2)])
74-
def test_first_with_first_day_last_of_month(self, frame_or_series, start, periods):
75-
# GH#29623
76-
x = frame_or_series([1] * 100, index=bdate_range(start, periods=100))
77-
result = x.first("1M")
78-
expected = frame_or_series(
79-
[1] * periods, index=bdate_range(start, periods=periods)
80-
)
81-
tm.assert_equal(result, expected)

0 commit comments

Comments
 (0)