Skip to content

BUG: datetime64[ns] conversion to object in DataFrame constructor inconsistent #2751

Closed
@jreback

Description

@jreback

this seems to happend when there is an object type passed as well

In [55]: df = pd.DataFrame({'a':[1,2,4,7], 
    'b':[1.2, 2.3, 5.1, 6.3], 
    'c':list('abcd'), 
    'd':[pd.datetime(2000,1,1) for i in range(4)]})

In [56]: df
Out[56]: 
   a    b  c                    d
0  1  1.2  a  2000-01-01 00:00:00
1  2  2.3  b  2000-01-01 00:00:00
2  4  5.1  c  2000-01-01 00:00:00
3  7  6.3  d  2000-01-01 00:00:00

In [57]: df.dtypes
Out[57]: 
a      int64
b    float64
c     object
d     object

# this is ok
In [64]: df = pd.DataFrame({'a':[1,2,4,7], 'b':[1.2, 2.3, 5.1, 6.3], 'd':[pd.datetime(2000,1,1) for i in range(4)]})

In [65]: df.dtypes
Out[65]: 
a             int64
b           float64
d    datetime64[ns]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions