Skip to content

Commit 72e923e

Browse files
BUG: date_range with freq="C" (business days) return value changed on 1.5.0 (#49610)
BUG: Use naive wall time to perform offsets datetime64 conversion
1 parent 9c05918 commit 72e923e

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

doc/source/whatsnew/v1.5.2.rst

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Fixed regressions
1717
- Fixed regression in :meth:`Series.replace` raising ``RecursionError`` with numeric dtype and when specifying ``value=None`` (:issue:`45725`)
1818
- Fixed regression in :meth:`DataFrame.plot` preventing :class:`~matplotlib.colors.Colormap` instance
1919
from being passed using the ``colormap`` argument if Matplotlib 3.6+ is used (:issue:`49374`)
20+
- Fixed regression in :func:`date_range` returning an invalid set of periods for ``CustomBusinessDay`` frequency and ``start`` date with timezone (:issue:`49441`)
2021
-
2122

2223
.. ---------------------------------------------------------------------------

pandas/_libs/tslibs/offsets.pyx

+3-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,9 @@ cdef _to_dt64D(dt):
254254
if getattr(dt, 'tzinfo', None) is not None:
255255
# Get the nanosecond timestamp,
256256
# equiv `Timestamp(dt).value` or `dt.timestamp() * 10**9`
257-
naive = dt.astimezone(None)
257+
# The `naive` must be the `dt` naive wall time
258+
# instead of the naive absolute time (GH#49441)
259+
naive = dt.replace(tzinfo=None)
258260
dt = np.datetime64(naive, "D")
259261
else:
260262
dt = np.datetime64(dt)

pandas/tests/indexes/datetimes/test_date_range.py

+18
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,24 @@ def test_range_with_millisecond_resolution(self, start_end):
11511151
expected = DatetimeIndex([start])
11521152
tm.assert_index_equal(result, expected)
11531153

1154+
@pytest.mark.parametrize(
1155+
"start,period,expected",
1156+
[
1157+
("2022-07-23 00:00:00+02:00", 1, ["2022-07-25 00:00:00+02:00"]),
1158+
("2022-07-22 00:00:00+02:00", 1, ["2022-07-22 00:00:00+02:00"]),
1159+
(
1160+
"2022-07-22 00:00:00+02:00",
1161+
2,
1162+
["2022-07-22 00:00:00+02:00", "2022-07-25 00:00:00+02:00"],
1163+
),
1164+
],
1165+
)
1166+
def test_range_with_timezone_and_custombusinessday(self, start, period, expected):
1167+
# GH49441
1168+
result = date_range(start=start, periods=period, freq="C")
1169+
expected = DatetimeIndex(expected)
1170+
tm.assert_index_equal(result, expected)
1171+
11541172

11551173
def test_date_range_with_custom_holidays():
11561174
# GH 30593

0 commit comments

Comments
 (0)