Skip to content

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

Open
@jbrockmendel

Description

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)

Metadata

Assignees

No one assigned

    Labels

    BugFrequencyDateOffsetsNon-Nanodatetime64/timedelta64 with non-nanosecond resolutionNumeric OperationsArithmetic, Comparison, and Logical operations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions