Skip to content

Commit 18c5cfd

Browse files
mroeschkejreback
authored andcommitted
BUG: Decrement start date with a negative, non-Tick frequency (#23278)
1 parent a2b4b4a commit 18c5cfd

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

doc/source/whatsnew/v0.24.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,7 @@ Datetimelike
996996
- Bug in rounding methods of :class:`DatetimeIndex` (:meth:`~DatetimeIndex.round`, :meth:`~DatetimeIndex.ceil`, :meth:`~DatetimeIndex.floor`) and :class:`Timestamp` (:meth:`~Timestamp.round`, :meth:`~Timestamp.ceil`, :meth:`~Timestamp.floor`) could give rise to loss of precision (:issue:`22591`)
997997
- Bug in :func:`to_datetime` with an :class:`Index` argument that would drop the ``name`` from the result (:issue:`21697`)
998998
- Bug in :class:`PeriodIndex` where adding or subtracting a :class:`timedelta` or :class:`Tick` object produced incorrect results (:issue:`22988`)
999+
- Bug in :func:`date_range` when decrementing a start date to a past end date by a negative frequency (:issue:`23270`)
9991000

10001001
Timedelta
10011002
^^^^^^^^^

pandas/tests/indexes/datetimes/test_date_range.py

+10
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,16 @@ def test_timezone_comparaison_assert(self):
510510
with tm.assert_raises_regex(AssertionError, msg):
511511
date_range(start, periods=2, tz='Europe/Berlin')
512512

513+
def test_negative_non_tick_frequency_descending_dates(self,
514+
tz_aware_fixture):
515+
# GH 23270
516+
tz = tz_aware_fixture
517+
result = pd.date_range(start='2011-06-01', end='2011-01-01',
518+
freq='-1MS', tz=tz)
519+
expected = pd.date_range(end='2011-06-01', start='2011-01-01',
520+
freq='1MS', tz=tz)[::-1]
521+
tm.assert_index_equal(result, expected)
522+
513523

514524
class TestGenRangeGeneration(object):
515525

pandas/tseries/offsets.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2388,7 +2388,7 @@ def generate_range(start=None, end=None, periods=None,
23882388
elif end and not offset.onOffset(end):
23892389
end = offset.rollback(end)
23902390

2391-
if periods is None and end < start:
2391+
if periods is None and end < start and offset.n >= 0:
23922392
end = None
23932393
periods = 0
23942394

0 commit comments

Comments
 (0)