From 4bfdd388bb3ba53b39680abd9716851095da6b0e Mon Sep 17 00:00:00 2001 From: goodboy Date: Sun, 18 Jan 2026 14:19:51 -0500 Subject: [PATCH] Fix polars 1.36.0 duration API Polars tightened type safety for `.dt` accessor methods requiring `total_*` methods for duration types vs datetime component accessors like `day()` which now only work on datetime dtypes. `detect_time_gaps()` in `.tsp._anal` was calling `.dt.day()` on `dt_diff` column (a duration from `.diff()`) which throws `InvalidOperationError` on modern polars. Changes: - use f-string to add pluralization to map time unit strings to `total_s` form for the new duration API. - Handle singular/plural forms: 'day' -> 'days' -> 'total_days' - Ensure trailing 's' before applying 'total_' prefix Also updates inline comments explaining the polars type distinction between datetime components vs duration totals. Fixes `piker store ldshm` crashes on datasets with time gaps. (this patch was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code --- piker/tsp/_anal.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/piker/tsp/_anal.py b/piker/tsp/_anal.py index 42c3aa6c..26c3740e 100644 --- a/piker/tsp/_anal.py +++ b/piker/tsp/_anal.py @@ -578,11 +578,22 @@ def detect_time_gaps( # NOTE: this flag is to indicate that on this (sampling) time # scale we expect to only be filtering against larger venue # closures-scale time gaps. + # + # Map to total_ method since `dt_diff` is a duration type, + # not datetime - modern polars requires `total_*` methods + # for duration types (e.g. `total_days()` not `day()`) + # Ensure plural form for polars API (e.g. 'day' -> 'days') + unit_plural: str = ( + gap_dt_unit + if gap_dt_unit.endswith('s') + else f'{gap_dt_unit}s' + ) + duration_method: str = f'total_{unit_plural}' return step_gaps.filter( # Second by an arbitrary dt-unit step size getattr( pl.col('dt_diff').dt, - gap_dt_unit, + duration_method, )().abs() > gap_thresh )