<h4 dir="auto">Code Sample, a copy-pastable example if possible</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import win32timezone
import pywintypes
import pandas

d = pywintypes.TimeType(2001, 1, 1, tzinfo=win32timezone.TimeZoneInfo('Eastern Standard Time'))

ix = pandas.Index([d])  ## crash occurs here"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">win32timezone</span>
<span class="pl-k">import</span> <span class="pl-s1">pywintypes</span>
<span class="pl-k">import</span> <span class="pl-s1">pandas</span>

<span class="pl-s1">d</span> <span class="pl-c1">=</span> <span class="pl-s1">pywintypes</span>.<span class="pl-v">TimeType</span>(<span class="pl-c1">2001</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-s1">tzinfo</span><span class="pl-c1">=</span><span class="pl-s1">win32timezone</span>.<span class="pl-v">TimeZoneInfo</span>(<span class="pl-s">'Eastern Standard Time'</span>))

<span class="pl-s1">ix</span> <span class="pl-c1">=</span> <span class="pl-s1">pandas</span>.<span class="pl-v">Index</span>([<span class="pl-s1">d</span>])  <span class="pl-c">## crash occurs here</span></pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">In the example above, tzinfo.utcoffset(None) returns None. In tslib.pyx _get_dst_info calls int(total_seconds(_get_utcoffset(tz, None))), and _get_utcoffset(tz, None) returns None. This causes a hard crash because total_seconds from datetime_helper.h expects a timedelta object, and crashes if the attributes "microseconds", "seconds" or "days" don't exist.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="// from datetime_helper.h
npy_int64 get_long_attr(PyObject *o, const char *attr) {
  npy_int64 long_val;
  PyObject *value = PyObject_GetAttrString(o, attr);  &lt;-- This returns NULL"><pre class="notranslate"><code class="notranslate">// from datetime_helper.h
npy_int64 get_long_attr(PyObject *o, const char *attr) {
  npy_int64 long_val;
  PyObject *value = PyObject_GetAttrString(o, attr);  &lt;-- This returns NULL
</code></pre></div>
<p dir="auto">When using a timezone from pytz the _utcoffset attribute is set, which is used by _get_utcoffset, and so this crash doesn't happen with that library.</p>
<h4 dir="auto">Expected Output</h4>
<p dir="auto">It shouldn't crash. Ideally it would handle these timezone types, but at least it should raise an Exception if the timezone type isn't currently supported.</p>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
INSTALLED VERSIONS
------------------
commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 78 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
<p dir="auto">pandas: 0.20.0rc1+6.g844013b20.dirty<br>
pytest: 3.0.5<br>
pip: 9.0.1<br>
setuptools: 34.3.3<br>
Cython: 0.25.2<br>
numpy: 1.11.2<br>
scipy: None<br>
xarray: None<br>
IPython: 5.3.0<br>
sphinx: 1.5.3<br>
patsy: None<br>
dateutil: 2.6.0<br>
pytz: 2016.10<br>
blosc: None<br>
bottleneck: None<br>
tables: None<br>
numexpr: None<br>
feather: None<br>
matplotlib: None<br>
openpyxl: 2.4.1<br>
xlrd: None<br>
xlwt: None<br>
xlsxwriter: 0.9.3<br>
lxml: None<br>
bs4: None<br>
html5lib: None<br>
sqlalchemy: 1.1.4<br>
pymysql: None<br>
psycopg2: 2.7.1 (dt dec pq3 ext lo64)<br>
jinja2: 2.9.5<br>
s3fs: None<br>
pandas_gbq: None<br>
pandas_datareader: None</p>
</details>
<p dir="auto">Thanks to the wonders of duck typing, <code class="notranslate">pandas.Timestamp</code> happily accepts <code class="notranslate">pywintypes.TimeType</code> objects (otherwise known as <code class="notranslate">pywintypes.datetime</code>), including those that employ the <code class="notranslate">win32timezone.TimeZoneInfo</code> object. And most methods work.</p>
<p dir="auto">For some reason, <code class="notranslate">to_datetime</code> does not, and indeed it crashes:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import pandas as pd
from win32timezone import TimeZoneInfo
from pywintypes import TimeType
x = TimeType(2012,12,1,0,0,tzinfo=TimeZoneInfo('GMT Standard TIme'))
y = pd.Timestamp(x)
print(y)
y.tzinfo
y.utcoffset()
y.to_datetime64()
y.to_datetime()"><pre class="notranslate"><code class="notranslate">import pandas as pd
from win32timezone import TimeZoneInfo
from pywintypes import TimeType
x = TimeType(2012,12,1,0,0,tzinfo=TimeZoneInfo('GMT Standard TIme'))
y = pd.Timestamp(x)
print(y)
y.tzinfo
y.utcoffset()
y.to_datetime64()
y.to_datetime()
</code></pre></div>
<p dir="auto">This occurs with Anaconda installed win64 Python 3.4.3 and Pandas 0.16.2.</p>
<p dir="auto">I'm going to see if I can't dig down to find a key source of failure. Stay tuned</p>