Description
Code Sample
# Your code here
import datetime, pandas as pd
data = [[datetime.datetime(2020, 2, 28, 13, 51, 27, tzinfo=datetime.timezone.utc)],
[datetime.datetime(2020, 2, 28, 13, 51, 27, tzinfo=datetime.timezone.utc)],
[datetime.datetime(2020, 2, 28, 13, 51, 27, tzinfo=datetime.timezone.utc)],
[datetime.datetime(2020, 2, 28, 13, 51, 27, tzinfo=datetime.timezone.utc)]]
df = pd.DataFrame(data, columns=['cd']) # dtype: datetime64[ns, UTC]
df2 = pd.DataFrame(index=df.index)
df2.loc[:,'cd2'] = df['cd'] # no error
df2.loc[df.index,'cd3'] = df['cd'] # error
df2.loc[df.index,'cd2'] = df['cd'] # no error
Problem description
If you try to assign datetime values (with zone and indexes) to a column, it will raise TypeError: data type not understood.
No errors raise with index ':', or when the column already has the correct type. Note that this only happens if the datetime has zone information. With tzinfo=None, no errors occur.
Output of pd.show_versions()
I noticed this bug in version 1.0.1
No errors occur in 0.25.3
INSTALLED VERSIONS
commit : None
pandas : 1.0.1
numpy : 1.16.4
pytz : 2019.1
dateutil : 2.8.0
pip : 20.0.1
setuptools : 45.1.0
Cython : None
pytest : None
hypothesis : None
sphinx : 2.4.2
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.8.2 (dt dec pq3 ext lo64)
jinja2 : 2.10.1
IPython : 7.8.0
pandas_datareader: None
bs4 : 4.8.2
bottleneck : None
fastparquet : None
gcsfs : 0.6.0
lxml.etree : None
matplotlib : 3.1.0
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 0.16.0
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : 1.2.0
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None