From 0bdedf81e238785b306c68062c983c110b440c22 Mon Sep 17 00:00:00 2001 From: FBumann <117816358+FBumann@users.noreply.github.com> Date: Mon, 27 Jul 2026 14:33:34 +0200 Subject: [PATCH] fix: support tsam_xarray 0.6.5 by using cluster_counts tsam_xarray 0.6.5 renamed AggregationResult.cluster_weights to cluster_counts, keeping the old name as a deprecated property. Because the test suite promotes warnings to errors, the resulting FutureWarning fails 254 of 286 clustering tests on any environment that resolves to 0.6.5 -- which the current `full` floor of >= 0.6.1 already permits. cluster_counts does not exist before 0.6.5, so the floor moves with the rename rather than merely allowing the new version. 0.6.5 also vectorises unsegmented disaggregation, which makes expand() ~3.6x faster with no changes on our side: 0.262s -> 0.073s on a 3-year, 40-cluster, 84-variable system (min of 10 runs). Co-Authored-By: Claude Opus 5 (1M context) --- flixopt/transform_accessor.py | 2 +- pyproject.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/flixopt/transform_accessor.py b/flixopt/transform_accessor.py index 30fc12a9d..579d4597b 100644 --- a/flixopt/transform_accessor.py +++ b/flixopt/transform_accessor.py @@ -88,7 +88,7 @@ def build_cluster_weights(self) -> xr.DataArray: Returns: DataArray with dims [cluster, period?, scenario?]. """ - return self._unrename(self._agg_result.cluster_weights.rename('cluster_weight')) + return self._unrename(self._agg_result.cluster_counts.rename('cluster_weight')) def build_typical_periods(self) -> dict[str, xr.DataArray]: """Build typical periods DataArrays with (cluster, time, ...) shape. diff --git a/pyproject.toml b/pyproject.toml index d9f6bc18b..f31fb7d16 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,7 +70,7 @@ tutorials = [ # Full feature set (everything except dev tools) full = [ - "tsam_xarray >= 0.6.1, < 1", # Time series aggregation for clustering (wraps tsam); 0.6.1 adds aggregate(cluster_on=) + "tsam_xarray >= 0.6.5, < 1", # Time series aggregation for clustering (wraps tsam); 0.6.5 renames cluster_weights to cluster_counts "tsam >= 3.4.0, < 4", # Directly imported for ClusterConfig, ExtremeConfig, SegmentConfig "pyvis==0.3.2", # Visualizing FlowSystem Network "scipy >= 1.15.1, < 2", # Used by tsam. Prior versions have conflict with highspy. See https://github.com/scipy/scipy/issues/22257 @@ -87,7 +87,7 @@ full = [ # Development tools and testing dev = [ "xarray<2026.5", # TODO: drop once linopy ships xarray 2026.3+ compat fix - "tsam_xarray==0.6.1", # Time series aggregation for clustering (wraps tsam) + "tsam_xarray==0.6.5", # Time series aggregation for clustering (wraps tsam) "tsam==3.4.0", # Directly imported for ClusterConfig, ExtremeConfig, SegmentConfig "pytest==9.1.1", "pytest-xdist==3.8.0",