Skip to content

BUG/API: fillna converts column of Timestamps to datetime64 #8189

@TomAugspurger

Description

@TomAugspurger

Not sure if this is intentional / known.

In [58]: tz = pd.DatetimeIndex(start='2010-01-01', periods=10, freq='d', tz='US/Central')

In [59]: df = pd.DataFrame(np.random.randn(10, 2), columns=['A', 'B'])

In [60]: df['time'] = tz

In [62]: df.dtypes
Out[62]: 
A       float64
B       float64
time     object
dtype: object

In [63]: df.fillna(0).dtypes
Out[63]: 
A              float64
B              float64
time    datetime64[ns]
dtype: object

Notice that the dtype of the time column changes from object (column of Timestamps) to datetime64[ns].
I think what's happening is the timestamps are being downcast:

In [64]: df.fillna(0, downcast=False).dtypes
Out[64]: 
A       float64
B       float64
time     object
dtype: object

The reason I worry about this as the default is because the timestamp information is lost.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolateTimezonesTimezone data dtype

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions