Skip to content

ValueError: Cannot compare tz-naive and tz-aware timestamps #6572

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

Closed
kontinuity opened this issue Mar 7, 2014 · 2 comments · Fixed by #7810
Closed

ValueError: Cannot compare tz-naive and tz-aware timestamps #6572

kontinuity opened this issue Mar 7, 2014 · 2 comments · Fixed by #7810
Labels
Bug Timezones Timezone data dtype
Milestone

Comments

@kontinuity
Copy link

Trying to generate a time series based on timezone raises exception.

>>> import pandas
>>> pandas.date_range('2013-01-01T00:00:00+05:30','2014-03-07T23:59:59+05:30',freq='AS')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/cruiser/work/metroleads/lib/python2.7/site-packages/pandas/tseries/index.py", line 1794, in date_range
    closed=closed)
  File "/Users/cruiser/work/metroleads/lib/python2.7/site-packages/pandas/tseries/index.py", line 196, in __new__
    infer_dst=infer_dst)
  File "/Users/cruiser/work/metroleads/lib/python2.7/site-packages/pandas/tseries/index.py", line 406, in _generate
    index = _generate_regular_range(start, end, periods, offset)
  File "/Users/cruiser/work/metroleads/lib/python2.7/site-packages/pandas/tseries/index.py", line 1750, in _generate_regular_range
    dates = list(xdr)
  File "/Users/cruiser/work/metroleads/lib/python2.7/site-packages/pandas/tseries/offsets.py", line 1871, in generate_range
    if periods is None and end < start:
  File "tslib.pyx", line 611, in pandas.tslib._Timestamp.__richcmp__ (pandas/tslib.c:10872)
  File "tslib.pyx", line 640, in pandas.tslib._Timestamp._assert_tzawareness_compat (pandas/tslib.c:11186)
ValueError: Cannot compare tz-naive and tz-aware timestamps
pandas==0.13.1
@jreback
Copy link
Contributor

jreback commented Mar 7, 2014

create this way

In [3]: pandas.date_range('2013-01-01T00:00:00','2014-03-07T23:59:59',freq='AS','US/Eastern')
Out[3]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-01-01 00:00:00, 2014-01-01 00:00:00]
Length: 2, Freq: AS-JAN, Timezone: US/Eastern

What you initially are suggesting requires a modification, want to do a pull-request for this?

@jreback jreback added this to the 0.15.0 milestone Mar 7, 2014
@sinhrks
Copy link
Member

sinhrks commented Jul 20, 2014

Can work on current master, maybe fixed in #7465. Will add test cases for this.

pd.date_range('2013-01-01T00:00:00+05:30','2014-03-07T23:59:59+05:30',freq='AS')
# <class 'pandas.tseries.index.DatetimeIndex'>
# [2013-01-01 00:00:00+05:30, 2014-01-01 00:00:00+05:30]
# Length: 2, Freq: AS-JAN, Timezone: tzoffset(None, 19800)

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

Successfully merging a pull request may close this issue.

3 participants