Skip to content

BUG: BDay() offsetting not behaving as expected #38324

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions pandas/tests/tseries/offsets/test_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
from pandas.compat.numpy import np_datetime64_compat
from pandas.errors import PerformanceWarning

from pandas import DatetimeIndex, Series, Timedelta, date_range, read_pickle
import pandas._testing as tm
from pandas.core.indexes.datetimes import DatetimeIndex, date_range
from pandas.core.series import Series

from pandas.io.pickle import read_pickle
from pandas.tseries.holiday import USFederalHolidayCalendar
import pandas.tseries.offsets as offsets
from pandas.tseries.offsets import (
Expand Down Expand Up @@ -2326,6 +2324,36 @@ def test_datetimeindex(self):
for idx in [idx1, idx2, idx3]:
tm.assert_index_equal(idx, expected)

def test_bday_ignores_timedeltas(self):
idx = date_range("2010/02/01", "2010/02/10", freq="12H")
t1 = idx + BDay(offset=Timedelta(3, unit="H"))

expected = DatetimeIndex(
Copy link
Member

Choose a reason for hiding this comment

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

i don't feel strongly about this but is there not a more concise way to generate this

Copy link
Member

Choose a reason for hiding this comment

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

Reducing the date range seems to be the way to go here. Maybe extend the freq too?

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

[
"2010-02-02 03:00:00",
"2010-02-02 15:00:00",
"2010-02-03 03:00:00",
"2010-02-03 15:00:00",
"2010-02-04 03:00:00",
"2010-02-04 15:00:00",
"2010-02-05 03:00:00",
"2010-02-05 15:00:00",
"2010-02-08 03:00:00",
"2010-02-08 15:00:00",
"2010-02-08 03:00:00",
"2010-02-08 15:00:00",
"2010-02-08 03:00:00",
"2010-02-08 15:00:00",
"2010-02-09 03:00:00",
"2010-02-09 15:00:00",
"2010-02-10 03:00:00",
"2010-02-10 15:00:00",
"2010-02-11 03:00:00",
],
freq=None,
)
tm.assert_index_equal(t1, expected)


class TestCustomBusinessHour(Base):
_offset = CustomBusinessHour
Expand Down