BUG: df.plot() with FixedOffset timezones · Issue #17173 · pandas-dev/pandas (original) (raw)

Code Sample, a copy-pastable example if possible

The following example will trigger an exception:

import pandas as pd import datetime

data = [] now = datetime.datetime.now(tz=datetime.timezone.utc) for i in range(10): data.append(dict(date=now + datetime.timedelta(days=i), data=i))

df = pd.DataFrame(data, index=[x['date'] for x in data])

df.plot()

This should fail with the error:

pandas/_libs/tslib.pyx in pandas._libs.tslib.dates_normalized (pandas/_libs/tslib.c:88136)()

AttributeError: 'datetime.timezone' object has no attribute '_transition_info'

Problem description

The "else" branch in this code will fail on instances of datetime.timezone which don't have a _transition_info internal field, which is true with objects like datetime.timezone.utc.

The code on master looks like this:

else:
    trans, deltas, typ = _get_dst_info(tz)

    for i in range(n):
        # Adjust datetime64 timestamp, recompute datetimestruct
        pos = trans.searchsorted(stamps[i]) - 1
        inf = tz._transition_info[pos]

        pandas_datetime_to_datetimestruct(stamps[i] + deltas[pos],
                                          PANDAS_FR_ns, &dts)
        if (dts.hour + dts.min + dts.sec + dts.us) > 0:
            return False

The problem is the setting of inf and its reference to _transition_info, but if I'm reading this code correctly, this is dead code anyway. With that line removed, this code should work with things like datetime.timezone.utc again.

Expected Output

I'd expect to be able to plot off timestamps which use datetime.timezone.utc as their timezone.

Output of pd.show_versions()

>>> pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.1.final.0
python-bits: 64
OS: Linux
OS-release: 4.10.0-27-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.20.2
pytest: None
pip: 9.0.1
setuptools: 27.2.0
Cython: None
numpy: 1.13.0
scipy: 0.19.1
xarray: None
IPython: 6.1.0
sphinx: None
patsy: None
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.0.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.999
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
pandas_gbq: None
pandas_datareader: None