Skip to content

The default resolution doesn't allow aggregating #46

Description

@dolegi

Title: Resolution mismatch causes cryptic error when aggregating - needs better handling or error message

Description:

When a TimeFrame has a very small default resolution (microseconds) and you try to aggregate to a much larger period (days), it fails with a cryptic Polars type conversion error instead of handling the case gracefully or providing a helpful error message.

Expected Behavior:

Either:

  • Automatically handle the resolution mismatch, or
  • Provide a clear error message explaining that the resolution needs to be adjusted before aggregating to the target period

Actual Behavior:

Fails with: polars.exceptions.InvalidOperationError: conversion from 'i128' to 'u32' failed in column 'scalar' for 1 out of 1 values: [86400000000]

Reproduction:

import time_stream as ts
from datetime import datetime, timedelta
import polars as pl

# Create sample data
dates = [datetime(2023, 1, 1) + timedelta(days=i) for i in range(10)]
temperatures = [20.5, 21.0, 19.1, 26.0, 24.2, 26.6, 28.4, 30.9, 31.0, 29.1]
precipitation = [0.0, 0.0, 5.1, 10.2, 2.0, 0.2, 0.0, 3.0, 1.6, 0.0]

df = pl.DataFrame({
    "time": dates,
    "temperature": temperatures,
    "precipitation": precipitation
})

tf = ts.TimeFrame(df=df, time_name="time")
print(tf)
# Shows: Resolution: PT0.000001S (microseconds)

# Attempt to aggregate to daily resolution
tf.aggregate('P1D', 'mean', 'precipitation')  # Fails with conversion error

Environment:

  • Python 3.12
  • time_stream (version from traceback paths)
  • polars (version from traceback paths)

Activity

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