Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: dt64[non_nano] + some_offsets incorrectly rounding #56586

Open
jbrockmendel opened this issue Dec 21, 2023 · 0 comments
Open

BUG: dt64[non_nano] + some_offsets incorrectly rounding #56586

jbrockmendel opened this issue Dec 21, 2023 · 0 comments
Labels
Bug Frequency DateOffsets Non-Nano datetime64/timedelta64 with non-nanosecond resolution Numeric Operations Arithmetic, Comparison, and Logical operations

Comments

@jbrockmendel
Copy link
Member

jbrockmendel commented Dec 21, 2023

import pandas as pd

dti  = pd.date_range("2016-01-01", periods=3, unit="s")

dti + pd.offsets.CustomBusinessDay(offset=pd.Timedelta(1))
dti + pd.offsets.BusinessHour(offset=pd.Timedelta(1))
dti + pd.offsets.CustomBusinessHour(offset=pd.Timedelta(1))
dti + pd.offsets.CustomBusinessMonthBegin(offset=pd.Timedelta(1))
dti + pd.offsets.CustomBusinessMonthEnd(offset=pd.Timedelta(1))

Each of the additions above incorrectly round the result when calling as_unit(self.unit) here.

The best solution would be to implement _apply_array for all of these offsets and make the pointwise path in _add_offset unnecessary.

Next best would be something like

res_unit = self.unit
if hasattr(offset, "offset"):
    unit = Timedelta(offset.offset).unit
    res_unit = max(self.unit, unit)  # <- not actually "max"; we probably have a helper for this
dtype = tz_to_dtype(self.tz, unit=res_unit)
result = type(self)._from_sequence(res_values, dtype=dtype)
@jbrockmendel jbrockmendel added Bug Numeric Operations Arithmetic, Comparison, and Logical operations Non-Nano datetime64/timedelta64 with non-nanosecond resolution Frequency DateOffsets labels Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Frequency DateOffsets Non-Nano datetime64/timedelta64 with non-nanosecond resolution Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

No branches or pull requests

1 participant