Skip to content

Commit

Permalink
Backport PR #49610 on branch 1.5.x (BUG: date_range with freq="C" (bu…
Browse files Browse the repository at this point in the history
…siness days) return value changed on 1.5.0) (#49625)

Backport PR #49610: BUG: date_range with freq="C" (business days) return value changed on 1.5.0

Co-authored-by: Douglas Lohmann <douglas.lohmann@mercadolivre.com>
  • Loading branch information
meeseeksmachine and douglaslohmann committed Nov 10, 2022
1 parent 0aab994 commit c8018b5
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 @@ -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 @@ -258,7 +258,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 @@ -1126,6 +1126,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 c8018b5

Please sign in to comment.