Skip to content

Incorrect dtype for concat with empty float and datetime columns #32934

Closed
@TomAugspurger

Description

@TomAugspurger

Code Sample, a copy-pastable example if possible

In [40]: a = pd.DataFrame({"A": pd.array(['2000'], dtype='datetime64[ns]')})

In [41]: b = pd.DataFrame({"A": pd.array([1.0], dtype='float64')})

In [42]: pd.concat([a.iloc[:0], b.iloc[:0]])['A'].dtype
Out[42]: dtype('<M8[ns]')

Problem description

The return dtype of concatentating a float64 and datetime64[ns] should be object dtype. That's typically the case when both are non-empty

In [45]: pd.concat([a, b])['A'].dtype
Out[45]: dtype('O')

But when either is empty, we get incorrect results

In [42]: pd.concat([a.iloc[:0], b.iloc[:0]])['A'].dtype
Out[42]: dtype('<M8[ns]')

In [43]: pd.concat([a.iloc[:0], b])['A'].dtype
Out[43]: dtype('float64')

In [44]: pd.concat([a, b.iloc[:0]])['A'].dtype
Out[44]: dtype('<M8[ns]')

All of those should be object dtype.

Metadata

Metadata

Assignees

Labels

BugDtype ConversionsUnexpected or buggy dtype conversionsNeeds TestsUnit test(s) needed to prevent regressionsReshapingConcat, Merge/Join, Stack/Unstack, Explodegood first issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions