Skip to content

fillna() containing timezone aware datetime64 rounded #14872

Closed
@brendene

Description

@brendene

Code Sample, a copy-pastable example if possible

import pandas as pd
import datetime, pytz

#Non-timezone aware datetime
s = pd.Series( [pd.NaT, pd.NaT, datetime.datetime(2016, 12, 12, 22, 24, 6, 100001) ] )
print(s)
0                          NaT
1                          NaT
2   2016-12-12 22:24:06.100001
dtype: datetime64[ns]

print(s.fillna(method='bfill'))
0   2016-12-12 22:24:06.100001
1   2016-12-12 22:24:06.100001
2   2016-12-12 22:24:06.100001
dtype: datetime64[ns]


# Timezone aware datetime
s = pd.Series( [pd.NaT, pd.NaT, datetime.datetime(2016, 12, 12, 22, 24, 6, 100001, tzinfo=pytz.utc) ] )
print(s)
0                                NaT
1                                NaT
2   2016-12-12 22:24:06.100001+00:00

print(s.fillna(method='bfill'))
0   2016-12-12 22:24:06.100001024+00:00
1   2016-12-12 22:24:06.100001024+00:00
2   2016-12-12 22:24:06.100001024+00:00
dtype: datetime64[ns, UTC]

Problem description

This is similar to bug #6587 but difference is a timezone aware datetime. It looks like the dtype is being stripped and the value is converted to a float and back.

Expected Output

s = pd.Series( [pd.NaT, pd.NaT, datetime.datetime(2016, 12, 12, 22, 24, 6, 100001, tzinfo=pytz.utc) ] )
print(s)
0                                NaT
1                                NaT
2   2016-12-12 22:24:06.100001+00:00

print(s.fillna(method='bfill'))
0   2016-12-12 22:24:06.100001000+00:00
1   2016-12-12 22:24:06.100001000+00:00
2   2016-12-12 22:24:06.100001000+00:00
dtype: datetime64[ns, UTC]

Output of pd.show_versions()

pandas: 0.19.1 numpy: 1.11.2 scipy: 0.18.1 pytz: 2016.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDatetimeDatetime data dtypeMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions