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: date_range with freq="C" (business days) return value changed on 1.5.0 #49610

Merged
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.5.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Fixed regressions
- Fixed regression in :meth:`Series.replace` raising ``RecursionError`` with numeric dtype and when specifying ``value=None`` (:issue:`45725`)
- Fixed regression in :meth:`DataFrame.plot` preventing :class:`~matplotlib.colors.Colormap` instance
from being passed using the ``colormap`` argument if Matplotlib 3.6+ is used (:issue:`49374`)
- Fixed regression in :func:`date_range` returning an invalid set of periods for ``CustomBusinessDay`` frequency and ``start`` date with timezone (:issue:`49441`)
-

.. ---------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ cdef _to_dt64D(dt):
if getattr(dt, 'tzinfo', None) is not None:
# Get the nanosecond timestamp,
# equiv `Timestamp(dt).value` or `dt.timestamp() * 10**9`
naive = dt.astimezone(None)
# The `naive` must be the `dt` naive wall time
# instead of the naive absolute time (GH#49441)
naive = dt.replace(tzinfo=None)
lohmanndouglas marked this conversation as resolved.
Show resolved Hide resolved
dt = np.datetime64(naive, "D")
else:
dt = np.datetime64(dt)
Expand Down
18 changes: 18 additions & 0 deletions pandas/tests/indexes/datetimes/test_date_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,24 @@ def test_range_with_millisecond_resolution(self, start_end):
expected = DatetimeIndex([start])
tm.assert_index_equal(result, expected)

@pytest.mark.parametrize(
"start,period,expected",
[
("2022-07-23 00:00:00+02:00", 1, ["2022-07-25 00:00:00+02:00"]),
("2022-07-22 00:00:00+02:00", 1, ["2022-07-22 00:00:00+02:00"]),
(
"2022-07-22 00:00:00+02:00",
2,
["2022-07-22 00:00:00+02:00", "2022-07-25 00:00:00+02:00"],
),
],
)
def test_range_with_timezone_and_custombusinessday(self, start, period, expected):
# GH49441
result = date_range(start=start, periods=period, freq="C")
expected = DatetimeIndex(expected)
tm.assert_index_equal(result, expected)


def test_date_range_with_custom_holidays():
# GH 30593
Expand Down