Can't initialise DataFrame with ExtensionDtype, but can do so for Series · Issue #30280 · pandas-dev/pandas (original) (raw)

Code Sample, a copy-pastable example if possible

import pandas as pd import pytz

temp = pd.Series([pd.Timestamp("2019-07-19 07:04:57+0100", tz=pytz.FixedOffset(60))]) pd.Series(["2019-06-19 07:04:57"], dtype=temp.dtype) # works pd.DataFrame(["2019-06-19 07:04:57"]).astype(temp.dtype) # works pd.DataFrame(["2019-06-19 07:04:57"], dtype=temp.dtype) # fails

Problem description

I get the following error:

ValueError: failed to cast to 'datetime64[ns, pytz.FixedOffset(60)]' (Exception was: data type not understood)

Expected Output

I would have expected the same output as I got in the first two examples above labelled #works.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.7.4.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-70-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8

pandas : 0.25.3
numpy : 1.17.4
pytz : 2019.3
dateutil : 2.8.0
pip : 19.3.1
setuptools : 41.4.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 7.9.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None