Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[ ] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
In [1]: import pandas as pd
In [2]: s = pd.Series(["2020-05-31 08:00:00", "2000-12-31 04:00:05", "1800-03-14 07:30:20"], dtype='datetime64[ms]')
In [3]: s
Out[3]:
0 2020-05-31 08:00:00
1 2000-12-31 04:00:05
2 1800-03-14 07:30:20
dtype: datetime64[ms]
In [4]: s.dt.round('U')
/nvme/0/pgali/envs/cudfdev/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py:2006: RuntimeWarning: divide by zero encountered in divmod
result_i8 = round_nsint64(values, mode, nanos)
Out[4]:
0 1970-01-01
1 1970-01-01
2 1970-01-01
dtype: datetime64[ms]
Issue Description
Performing a rounding operation of resolution lesser than the dtype, or when there is sub-second data and the rounding resolution is a sub-second data should ideally be a no-op. Instead we seem to be running into division by zero scenario and returning incorrect results.
Expected Behavior
In [3]: s.dt.round('U')
Out[3]:
0 2020-05-31 08:00:00
1 2000-12-31 04:00:05
2 1800-03-14 07:30:20
dtype: datetime64[ms]
Installed Versions
Comment From: galipremsagar
cc: @mroeschke
Comment From: jbrockmendel
on main this raises ZeroDivisionError, which is at least slightly better than silently giving incorrect results. PR to fix this would be welcome.
Comment From: Lokeshrathi
If someone is working on this, can we please connect and work on this. As I am a newbie here and would love to learn and explore pandas, since I use it on a day-to-day basis.
I am fine with any hour of the day. :-)