Skip to content

BUG: Decrement start date with a negative, non-Tick frequency #23278

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

Merged
merged 2 commits into from
Oct 23, 2018
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/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ Datetimelike
- 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`)
- Bug in :func:`to_datetime` with an :class:`Index` argument that would drop the ``name`` from the result (:issue:`21697`)
- Bug in :class:`PeriodIndex` where adding or subtracting a :class:`timedelta` or :class:`Tick` object produced incorrect results (:issue:`22988`)
- Bug in :func:`date_range` when decrementing a start date to a past end date by a negative frequency (:issue:`23270`)

Timedelta
^^^^^^^^^
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/indexes/datetimes/test_date_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,16 @@ def test_timezone_comparaison_assert(self):
with tm.assert_raises_regex(AssertionError, msg):
date_range(start, periods=2, tz='Europe/Berlin')

def test_negative_non_tick_frequency_descending_dates(self,
tz_aware_fixture):
# GH 23270
tz = tz_aware_fixture
result = pd.date_range(start='2011-06-01', end='2011-01-01',
freq='-1MS', tz=tz)
expected = pd.date_range(end='2011-06-01', start='2011-01-01',
freq='1MS', tz=tz)[::-1]
tm.assert_index_equal(result, expected)


class TestGenRangeGeneration(object):

Expand Down
2 changes: 1 addition & 1 deletion pandas/tseries/offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2388,7 +2388,7 @@ def generate_range(start=None, end=None, periods=None,
elif end and not offset.onOffset(end):
end = offset.rollback(end)

if periods is None and end < start:
if periods is None and end < start and offset.n >= 0:
end = None
periods = 0

Expand Down