Skip to content

'Cannot compare tz-naive and tz-aware timestamps' when plotting series #2877

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
kdebrab opened this issue Feb 15, 2013 · 3 comments
Closed
Labels
Milestone

Comments

@kdebrab
Copy link
Contributor

kdebrab commented Feb 15, 2013

Pandas version 0.10.1:

import pandas as pd
index = pd.date_range('1/1/2011', periods=2, freq='H', tz='Europe/Brussels')
ts = pd.Series([188.5, 328.25], index=index)
ts.plot()

yields the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\pandas\tools\plotting.py", line 1534, in plot_series
    plot_obj.generate()
  File "C:\Python27\lib\site-packages\pandas\tools\plotting.py", line 735, in generate
    self._make_plot()
  File "C:\Python27\lib\site-packages\pandas\tools\plotting.py", line 1076, in _make_plot
    if not self.x_compat and self.use_index and self._use_dynamic_x():
  File "C:\Python27\lib\site-packages\pandas\tools\plotting.py", line 1057, in _use_dynamic_x
    return (freq is not None) and self._is_dynamic_freq(freq)
  File "C:\Python27\lib\site-packages\pandas\tools\plotting.py", line 1030, in _is_dynamic_freq
    return freq is not None and self._no_base(freq)
  File "C:\Python27\lib\site-packages\pandas\tools\plotting.py", line 1043, in _no_base
    return Period(x[0], freq).to_timestamp() == x[0]
  File "tslib.pyx", line 434, in pandas.tslib._Timestamp.__richcmp__ (pandas\tslib.c:7930)
  File "tslib.pyx", line 484, in pandas.tslib._Timestamp._assert_tzawareness_compat (pandas\tslib.c:8528)
Exception: Cannot compare tz-naive and tz-aware timestamps
@adamgreenhall
Copy link
Contributor

Encountered this as well. Workaround:

import pandas as pd
index = pd.date_range('1/1/2011', periods=2, freq='H', tz='Europe/Brussels')
ts = pd.Series([188.5, 328.25], index=index)

ts_no_tz = ts.copy()
ts_no_tz.index.tz = None
ts_no_tz.plot()

or:

pd.Series(ts, index=ts.index.tz_convert(None), copy=True).plot()

@ghost
Copy link

ghost commented Mar 7, 2013

can you try out #2991?

@ghost
Copy link

ghost commented Mar 15, 2013

fixed in master.

@ghost ghost closed this as completed Mar 15, 2013
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants