Skip to content

feat(ai): add client.ai.time_series.impute_with_retrieval - #2880

Draft
miladh wants to merge 1 commit into
ai-ts-forecasting/07-data-forecastfrom
ai-ts-forecasting/08-data-impute
Draft

miladh wants to merge 1 commit into
ai-ts-forecasting/07-data-forecastfrom
ai-ts-forecasting/08-data-impute

Conversation

@miladh

@miladh miladh commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #2879

Description

Adds client.ai.time_series.impute_with_retrieval(...), which reconstructs gaps and chosen datapoints of CDF time series by instance id. Retrieval and alignment work as in client.ai.time_series.forecast_with_retrieval.

Callers must say what to reconstruct, so nothing is imputed by accident:

  • fill_gaps=True reconstructs every grid point without a datapoint. With aggregates, that's every empty bucket.
  • mask=[...] takes timestamps, or inclusive (start, end) ranges, to reconstruct even where values exist, for example a known-bad period. A mask that covers no grid point raises ValueError.

Passing neither raises ValueError before any data is retrieved. One instance id returns a TimeSeriesImpute; several return a TimeSeriesImputeList.

Only touches AITimeSeriesAPI and its generated sync file. No existing datapoints files are changed.

Usage

from datetime import datetime, timezone
from cognite.client import CogniteClient
from cognite.client.data_classes.data_modeling import NodeId

client = CogniteClient()
node = NodeId("my_space", "21-PT-1019")

# Fill every empty 10-minute bucket in the last week -> TimeSeriesImpute
res = client.ai.time_series.impute_with_retrieval(
    instance_id=node, start="7d-ago", granularity="10m", aggregate="average", fill_gaps=True
)
res.to_pandas()   # reconstructed points: DatetimeIndex, one column per quantile level

# Reconstruct a period you know is bad, e.g. during a sensor fault
res = client.ai.time_series.impute_with_retrieval(
    instance_id=node, start="7d-ago", granularity="10m", aggregate="average",
    mask=[(datetime(2026, 9, 30, 8, tzinfo=timezone.utc), datetime(2026, 9, 30, 12, tzinfo=timezone.utc))],
)

# Not saying what to reconstruct raises, before anything is retrieved:
client.ai.time_series.impute_with_retrieval(instance_id=node, start="7d-ago")
# ValueError: Say what to reconstruct: pass `fill_gaps=True`, `mask=[...]`, or both.

Checklist:

  • Tests added/updated: TestImputeWithRetrieval in test_ai_time_series_retrieval.py.
  • Documentation updated: docstrings, rendered in the existing ai.rst section.
  • The PR title follows the Conventional Commit spec.

🤖 Generated with Claude Code

@miladh
miladh force-pushed the ai-ts-forecasting/08-data-impute branch from cf6ac62 to 7dfbfb5 Compare October 30, 2026 07:49
@miladh miladh changed the title feat(ai): add client.ai.time_series.data.impute feat(ai): add client.ai.time_series.impute_with_retrieval Oct 30, 2026
Reconstruct gaps and chosen datapoints of CDF time series by
instance_id. Retrieval and alignment work as in
client.ai.time_series.forecast_with_retrieval; the request goes to
client.ai.time_series.impute.

Callers must say what to reconstruct, so nothing is imputed by accident:
- fill_gaps=True reconstructs every grid point without a datapoint (with
  aggregates, every empty bucket).
- mask=[...] hides timestamps or inclusive (start, end) ranges from the
  model and reconstructs them even where values exist, e.g. a known-bad
  period. A mask that covers no grid point raises ValueError.

A single instance_id returns a TimeSeriesImpute; several return a
TimeSeriesImputeList.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@miladh
miladh force-pushed the ai-ts-forecasting/08-data-impute branch from 7dfbfb5 to ea2d5a6 Compare November 2, 2026 11:15
@miladh
miladh force-pushed the ai-ts-forecasting/07-data-forecast branch from 1cb93d7 to e26972f Compare November 2, 2026 11:15

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant