Skip to content

Commit

Permalink
BUG: date_range with freq="C" (business days) return value changed on…
Browse files Browse the repository at this point in the history
… 1.5.0 (#49610)

BUG: Use naive wall time to perform offsets datetime64 conversion
  • Loading branch information
douglaslohmann authored Nov 10, 2022
1 parent 9c05918 commit 72e923e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
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 @@ -17,6 +17,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)
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

0 comments on commit 72e923e

Please sign in to comment.