Skip to content

BUG: resample with datetime64 data on series looses dtype #13119

@jorisvandenbossche

Description

@jorisvandenbossche

From SO: http://stackoverflow.com/questions/37106810/bug-in-python-pandas-pandas-series-resample-vs-pandas-dataframe-resample

In [7]: import datetime as dt

In [8]: df = pd.DataFrame([[dt.datetime(2016,1,31,15)], [dt.datetime(2016,2,7,17)]], index=[dt.datetime(2016,1,31,15), dt.datetime(2016,2,7,17)], columns=['timestamp'])

In [10]: df
Out[10]:
                              timestamp
2016-01-31 15:00:00 2016-01-31 15:00:00
2016-02-07 17:00:00 2016-02-07 17:00:00

In [11]: df.resample('D').first().timestamp
Out[11]:
2016-01-31   2016-01-31 15:00:00
2016-02-01                   NaT
2016-02-02                   NaT
2016-02-03                   NaT
2016-02-04                   NaT
2016-02-05                   NaT
2016-02-06                   NaT
2016-02-07   2016-02-07 17:00:00
Freq: D, Name: timestamp, dtype: datetime64[ns]

In [12]: df.timestamp.resample('D').first()
Out[12]:
2016-01-31    1.454252e+18
2016-02-01             NaN
2016-02-02             NaN
2016-02-03             NaN
2016-02-04             NaN
2016-02-05             NaN
2016-02-06             NaN
2016-02-07    1.454864e+18
Freq: D, Name: timestamp, dtype: float64

Tested it with latest master

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugResampleresample methodTestingpandas testing functions or related to the test suite

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions