Skip to content

datetime64[ns] dtype coerced to object after pd.concat(axis=1) #28786

Closed
@atlasstrategic

Description

@atlasstrategic

Code example using pandas 0.25.1

import pandas as pd

df1 = pd.DataFrame([], index=[], columns = ["foo"])
df2 = pd.DataFrame(data=list(range(20)),index=pd.date_range(start='2000', end='2020', freq='A-DEC'),columns=["bar"])
print(df2.index.dtype.name)
# Output: `datetime64[ns]`

df = pd.concat([df1, df2], axis=1)
print(df.index.dtype.name)
# Output: `object`

Problem description

The expected dtype of the concatenated DataFrame df should be datetime64[ns]. Previously, with Pandas 0.24.2, this was the case. After upgrading to pandas 0.25.1 it changed to object.

Output of pd.show_versions()

INSTALLED VERSIONS

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

pandas : 0.25.1
numpy : 1.17.2
pytz : 2019.2
dateutil : 2.8.0
pip : 19.2.3
setuptools : 40.4.3
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 1.2.1
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.8.3 (dt dec pq3 ext lo64)
jinja2 : 2.10
IPython : None
pandas_datareader: None
bs4 : 4.8.0
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : 3.0.0
pandas_gbq : None
pyarrow : 0.14.1
pytables : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : 1.2.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDtype ConversionsUnexpected or buggy dtype conversionsReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions