`DataFrame.diff` on `datetime64` returns result inconsistent with `Series.diff`
See original GitHub issueCode Sample, a copy-pastable example if possible
>>> pd.Series(['NaT', '2019-01-01', '2019-01-02'], dtype='datetime64[ns]').diff()
0 NaT
1 NaT
2 1 days
dtype: timedelta64[ns]
>>> pd.Series(['NaT', '2019-01-01', '2019-01-02'], dtype='datetime64[ns]').to_frame().diff()
0
0 NaT
1 -88855 days +00:12:43.145224
2 1 days 00:00:00
Problem description
Doing .diff()
on a DataFrame
of datetime64
should yield exactly time deltas in exactly the same way as on the Series
i.e. index (1,0)
in the DataFrame
above should be NaT
, not an overflown timedelta64.
Output of pd.show_versions()
pandas : 1.0.1 numpy : 1.18.1 pytz : 2019.3 dateutil : 2.8.1 pip : 20.0.2 setuptools : 45.2.0.post20200210 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : None IPython : None pandas_datareader: None bs4 : None bottleneck : None fastparquet : None gcsfs : None lxml.etree : None matplotlib : None numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pytables : None pytest : None pyxlsb : None s3fs : None scipy : None sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None xlwt : None xlsxwriter : None numba : None
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
@shang-vikas: looks like you found the bug, nice one.
I think the code you are referring to is https://github.com/pandas-dev/pandas/blob/706e6427bd1afd05c82eae810d288bbe22ed21c8/pandas/core/algorithms.py#L1900 (Series) and https://github.com/pandas-dev/pandas/blob/9e69040f199266cd7a743dfd2f579f271337687f/pandas/_libs/algos.pyx#L1193 (DataFrame). I’m sure the pandas project would be very happy to have a PR fixing the DataFrame case to match the Series one.
@shang-vikas pull request would be welcome. it sounds like you’ve already done most of the work by identifying the source of the problem