<p dir="auto">As reported at pendulum, there are cases where creating a <code class="notranslate">date_range</code> fails with a segfault: <a href="https://github.com/sdispater/pendulum/issues/131" data-hovercard-type="issue" data-hovercard-url="/sdispater/pendulum/issues/131/hovercard">pendulum issues 131</a>.</p>
<h4 dir="auto">Code Sample</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="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])"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">datetime</span> <span class="pl-k">import</span> <span class="pl-s1">datetime</span>, <span class="pl-s1">timedelta</span>

<span class="pl-k">from</span> <span class="pl-s1">pendulum</span>.<span class="pl-s1">tz</span>.<span class="pl-s1">timezone</span> <span class="pl-k">import</span> <span class="pl-v">UTCTimezone</span>
<span class="pl-k">from</span> <span class="pl-s1">pendulum</span>.<span class="pl-s1">tz</span>.<span class="pl-s1">timezone_info</span> <span class="pl-k">import</span> <span class="pl-v">UTC</span>
<span class="pl-k">import</span> <span class="pl-s1">pandas</span> <span class="pl-k">as</span> <span class="pl-s1">pd</span>

<span class="pl-s1">tomorrow</span> <span class="pl-c1">=</span> <span class="pl-s1">datetime</span>.<span class="pl-en">now</span>() <span class="pl-c1">+</span> <span class="pl-en">timedelta</span>(<span class="pl-s1">hours</span><span class="pl-c1">=</span><span class="pl-c1">24</span>)
<span class="pl-s1">now</span> <span class="pl-c1">=</span> <span class="pl-s1">datetime</span>.<span class="pl-en">now</span>()

<span class="pl-s1">r</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">date_range</span>(<span class="pl-s1">now</span>, <span class="pl-s1">tomorrow</span>, <span class="pl-s1">freq</span><span class="pl-c1">=</span><span class="pl-s">'1H'</span>)

<span class="pl-s1">r</span>.<span class="pl-s1">tz</span> <span class="pl-c1">=</span> <span class="pl-v">UTC</span>
<span class="pl-c"># prints out the current date and time</span>
<span class="pl-en">print</span>(<span class="pl-s1">r</span>[<span class="pl-c1">0</span>])

<span class="pl-s1">r</span>.<span class="pl-s1">tz</span> <span class="pl-c1">=</span> <span class="pl-v">UTCTimezone</span>
<span class="pl-c"># seg faults</span>
<span class="pl-en">print</span>(<span class="pl-s1">r</span>[<span class="pl-c1">0</span>])</pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">As I understand it is allowed for <code class="notranslate">tzinfo</code> objects to return <code class="notranslate">None</code> for <code class="notranslate">utcoffset</code> according to the <a href="https://docs.python.org/3.6/library/datetime.html#datetime.tzinfo.utcoffset" rel="nofollow">Python docs</a>. However, in <a href="https://github.com/pandas-dev/pandas/blob/c8dafb5a7ae9fe42b9d15c47082a6fb139e78b5d/pandas/_libs/tslib.pyx#L4332">_get_dst_info</a> of <code class="notranslate">tslib</code> it is assumed <em>not</em> to return <code class="notranslate">None</code>. As I understand from the aforementioned <code class="notranslate">pendulum</code> ticket, it is correct to return <code class="notranslate">None</code> in this case.</p>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
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
<p dir="auto">pandas: 0.20.3<br>
pytest: 3.1.3<br>
pip: 9.0.1<br>
setuptools: 25.1.1<br>
Cython: None<br>
numpy: 1.13.1<br>
scipy: 0.19.1<br>
xarray: None<br>
IPython: 6.1.0<br>
sphinx: None<br>
patsy: None<br>
dateutil: 2.6.1<br>
pytz: 2017.2<br>
blosc: None<br>
bottleneck: None<br>
tables: None<br>
numexpr: None<br>
feather: None<br>
matplotlib: None<br>
openpyxl: None<br>
xlrd: None<br>
xlwt: None<br>
xlsxwriter: None<br>
lxml: None<br>
bs4: 4.6.0<br>
html5lib: None<br>
sqlalchemy: None<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: None<br>
s3fs: None<br>
pandas_gbq: None<br>
pandas_datareader: None</p>
</details>
<p dir="auto">xref <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="158265190" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/13351" data-hovercard-type="pull_request" data-hovercard-url="/pandas-dev/pandas/pull/13351/hovercard?comment_id=224614415&amp;comment_type=issue_comment" href="https://github.com/pandas-dev/pandas/pull/13351#issuecomment-224614415">#13351 (comment)</a></p>
<p dir="auto">We use <code class="notranslate">io/common/_get_handle</code> and <code class="notranslate">io/common/get_filepath_or_buffer</code> in various places in most of the io modules, need to unify encoding handling to a somewhat simpler interface (1 function).</p>