Describe the bug
TFTExplainer.explain() raises ValueError: The time index is missing the 'freq' attribute... when the target
TimeSeries uses a DatetimeIndex with resolution other than ns (e.g. datetime64[ms], common after reading
Parquet with pandas ≥ 2.0).
In darts/explainability/tft_explainer.py:224:
times = series.time_index[-icl:].union(pred_series.time_index)
attention = TimeSeries(values=..., times=times, components=...)
series.time_index is ms, pred_series.time_index (from model.predict) is ns. DatetimeIndex.union()
promotes both to ns and drops freq.
To Reproduce
import numpy as np, pandas as pd
from darts import TimeSeries
from darts.models import TFTModel
from darts.explainability import TFTExplainer
idx = pd.date_range("2026-02-12 09:15", periods=2880, freq="15min").as_unit("ms")
series = TimeSeries.from_times_and_values(
times=idx, values=np.random.rand(2880, 1).astype(np.float32), columns=["x"]
)
model = TFTModel(input_chunk_length=1, output_chunk_length=1,
add_relative_index=True, n_epochs=1).fit(series)
TFTExplainer(model, background_series=series).explain() # raises
Expected behavior
TFTExplainer.explain() should succeed for any regular-frequency TimeSeries, regardless of the DatetimeIndex
resolution.
System (please complete the following information):
- Python version: 3.14
- darts version: 0.43.0
- numpy version: 2.3.5
- pandas version: 2.3.3
Additional context
Workaround for users: df.index = df.index.as_unit("ns") before building the TimeSeries.
Describe the bug
TFTExplainer.explain()raisesValueError: The time index is missing the 'freq' attribute...when the targetTimeSeriesuses aDatetimeIndexwith resolution other thanns(e.g.datetime64[ms], common after readingParquet with pandas ≥ 2.0).
In
darts/explainability/tft_explainer.py:224:series.time_indexisms,pred_series.time_index(frommodel.predict) isns.DatetimeIndex.union()promotes both to
nsand dropsfreq.To Reproduce
Expected behavior
TFTExplainer.explain()should succeed for any regular-frequencyTimeSeries, regardless of theDatetimeIndexresolution.
System (please complete the following information):
Additional context
Workaround for users:
df.index = df.index.as_unit("ns")before building theTimeSeries.