Skip to content
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

BUG: date_range with negative, non-Tick frequencies returns empty DatetimeIndex #23270

Closed
mroeschke opened this issue Oct 21, 2018 · 2 comments · Fixed by #23278
Closed

BUG: date_range with negative, non-Tick frequencies returns empty DatetimeIndex #23270

mroeschke opened this issue Oct 21, 2018 · 2 comments · Fixed by #23278
Labels
Bug Datetime Datetime data dtype Frequency DateOffsets
Milestone

Comments

@mroeschke
Copy link
Member

Code Sample, a copy-pastable example if possible

In [40]: pd.__version__
Out[40]: '0.24.0.dev0+812.g5f051408f.dirty'
#Bug
In [41]: pd.date_range(start='2012-01-02', end='2011-01-02', freq='-1W')
Out[41]: DatetimeIndex([], dtype='datetime64[ns]', freq='-1W-SUN')
# Addition with a Timestamp works
In [42]: pd.Timestamp('2012-01-02') + pd.tseries.frequencies.to_offset('-1W')
Out[42]: Timestamp('2012-01-01 00:00:00')
# Tick-like frequencies work
In [43]: pd.date_range(start='2011-01-03', end='2011-01-02', freq='-12H')
Out[43]:
DatetimeIndex(['2011-01-03 00:00:00', '2011-01-02 12:00:00',
               '2011-01-02 00:00:00'],
              dtype='datetime64[ns]', freq='-12H')

Expected Output

In [45]: pd.date_range(end='2012-01-02', start='2011-01-02', freq='1W')[::-1]
Out[45]:
DatetimeIndex(['2012-01-01', '2011-12-25', '2011-12-18', '2011-12-11',
               '2011-12-04', '2011-11-27', '2011-11-20', '2011-11-13',
               '2011-11-06', '2011-10-30', '2011-10-23', '2011-10-16',
               '2011-10-09', '2011-10-02', '2011-09-25', '2011-09-18',
               '2011-09-11', '2011-09-04', '2011-08-28', '2011-08-21',
               '2011-08-14', '2011-08-07', '2011-07-31', '2011-07-24',
               '2011-07-17', '2011-07-10', '2011-07-03', '2011-06-26',
               '2011-06-19', '2011-06-12', '2011-06-05', '2011-05-29',
               '2011-05-22', '2011-05-15', '2011-05-08', '2011-05-01',
               '2011-04-24', '2011-04-17', '2011-04-10', '2011-04-03',
               '2011-03-27', '2011-03-20', '2011-03-13', '2011-03-06',
               '2011-02-27', '2011-02-20', '2011-02-13', '2011-02-06',
               '2011-01-30', '2011-01-23', '2011-01-16', '2011-01-09',
               '2011-01-02'],
              dtype='datetime64[ns]', freq='-1W-SUN')
@mroeschke mroeschke added Bug Datetime Datetime data dtype Frequency DateOffsets labels Oct 21, 2018
@srinivasreddy
Copy link
Contributor

I will take it.

@mroeschke
Copy link
Member Author

Sorry @srinivasreddy I just created a PR with a patch, but feel free to take up any other issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype Frequency DateOffsets
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants