Skip to content

offset_times with an array n truncates offsets finer than the times' resolution #304

Closed

Description

For non-Tick offsets, _offset_times_array_n casts the result back to the input resolution. An offset finer than that resolution is silently dropped with an array n, while a scalar n keeps it:

import numpy as np
import pandas as pd
from utilsforecast.processing import offset_times

s = pd.Series(pd.to_datetime(["2020-01-01", "2020-01-31"])).astype("datetime64[s]")
off = pd.DateOffset(milliseconds=500)
offset_times(s, off, 1)                 # 00:00:00.5, datetime64[ms]
offset_times(s, off, np.array([1, 1]))  # 00:00:00,   datetime64[s]

This path also emits a pandas FutureWarning ("The behavior of array concatenation with empty entries is deprecated") from dt_index[:0].append(runs) when the runs have a finer unit than the input.

Proposed fix: drop the final cast in _offset_times_array_n so an array n keeps the computed resolution, as a scalar n and the Tick path already do. This changes the output dtype for these inputs.

time_ranges has a similar truncation (it casts to starts.dtype), e.g. time_ranges(<datetime64[s] series>, "500ms", 2) repeats each start.

Found while reviewing #303.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions