As reported at pendulum, there are cases where creating a date_range fails with a segfault: pendulum issues 131.

Code Sample

from datetime import datetime, timedelta

from pendulum.tz.timezone import UTCTimezone
from pendulum.tz.timezone_info import UTC
import pandas as pd

tomorrow = datetime.now() + timedelta(hours=24)
now = datetime.now()

r = pd.date_range(now, tomorrow, freq='1H')

r.tz = UTC
# prints out the current date and time
print(r[0])

r.tz = UTCTimezone
# seg faults
print(r[0])

Problem description

As I understand it is allowed for tzinfo objects to return None for utcoffset according to the Python docs. However, in _get_dst_info of tslib it is assumed not to return None. As I understand from the aforementioned pendulum ticket, it is correct to return None in this case.

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.5.3.final.0 python-bits: 64 OS: Linux OS-release: 4.11.3-200.fc25.x86_64 machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_GB.UTF-8 LOCALE: en_GB.UTF-8 pandas: 0.20.3 pytest: 3.1.3 pip: 9.0.1 setuptools: 25.1.1 Cython: None numpy: 1.13.1 scipy: 0.19.1 xarray: None IPython: 6.1.0 sphinx: None patsy: None dateutil: 2.6.1 pytz: 2017.2 blosc: None bottleneck: None tables: None numexpr: None feather: None matplotlib: None openpyxl: None xlrd: None xlwt: None xlsxwriter: None lxml: None bs4: 4.6.0 html5lib: None sqlalchemy: None pymysql: None psycopg2: None jinja2: None s3fs: None pandas_gbq: None pandas_datareader: None

Comment From: jreback

duplicate issue of https://github.com/pandas-dev/pandas/issues/15986, see discussion there.

Comment From: frensjan

@jreback sorry, missed that one. Still think that it would be good if pandas doesn't segfault on a valid response from a timezone object (valid as in that according to the python docs a timezone object is allowed to return None).

Comment From: jreback

@frensjan if you want to make a PR that uses a mock timezone object would be great.

Still think that it would be good if pandas doesn't segfault on a valid response from a timezone object (valid as in that according to the python docs a timezone object is allowed to return None).

I am not so sure that this library complies.