-
Notifications
You must be signed in to change notification settings - Fork 0
feat: support tsam v4 (cluster_counts rename, ClusterConfig.weights removal) #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| from __future__ import annotations | ||
|
|
||
| import warnings | ||
| from dataclasses import dataclass | ||
| from typing import TYPE_CHECKING | ||
|
|
||
|
|
@@ -66,8 +67,10 @@ class AggregationResult: | |
| *slice_dims)``. | ||
| cluster_assignments: Which cluster each period | ||
| belongs to. Dims: ``(period, *slice_dims)``. | ||
| cluster_weights: Periods per cluster. | ||
| Dims: ``(cluster, *slice_dims)``. | ||
| cluster_counts: Periods per cluster. | ||
| Dims: ``(cluster, *slice_dims)``. Formerly | ||
| ``cluster_weights``, which remains as a deprecated | ||
| alias (following tsam v4's rename). | ||
| segment_durations: Duration of each segment, or | ||
| ``None``. Dims: ``(cluster, timestep, | ||
| *slice_dims)``. | ||
|
|
@@ -83,7 +86,7 @@ class AggregationResult: | |
|
|
||
| cluster_representatives: xr.DataArray | ||
| cluster_assignments: xr.DataArray | ||
| cluster_weights: xr.DataArray | ||
| cluster_counts: xr.DataArray | ||
| segment_durations: xr.DataArray | None | ||
| accuracy: AccuracyMetrics | ||
| reconstructed: xr.DataArray | ||
|
|
@@ -109,10 +112,25 @@ def dim_names(self) -> DimNames: | |
| """Names of the structural output dimensions. See `DimNames`.""" | ||
| return self.clustering.dim_names | ||
|
|
||
| @property | ||
| def cluster_weights(self) -> xr.DataArray: | ||
| """Deprecated alias for `cluster_counts`. | ||
|
|
||
| Renamed to match tsam v4, where the values are occurrence counts | ||
| rather than weights. Will be removed in a future release. | ||
| """ | ||
| warnings.warn( | ||
| "AggregationResult.cluster_weights is deprecated; use " | ||
| "cluster_counts instead.", | ||
| FutureWarning, | ||
| stacklevel=2, | ||
| ) | ||
| return self.cluster_counts | ||
|
|
||
| @property | ||
| def n_clusters(self) -> int: | ||
| """Number of cluster representative clusters.""" | ||
| return int(self.cluster_weights.sizes[self.dim_names.cluster]) | ||
| return int(self.cluster_counts.sizes[self.dim_names.cluster]) | ||
|
Comment on lines
+115
to
+133
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win Complete the changed docstrings with the required Google-style sections. The same documentation-contract gap appears across the changed source files.
As per coding guidelines, 📍 Affects 2 files
🤖 Prompt for AI AgentsSource: Coding guidelines |
||
|
|
||
| @property | ||
| def n_timesteps_per_period(self) -> int: | ||
|
|
@@ -249,7 +267,7 @@ def _make_slice_view(self, sel: dict[str, object]) -> AggregationResult: | |
| return AggregationResult( | ||
| cluster_representatives=self.cluster_representatives.sel(sel), | ||
| cluster_assignments=self.cluster_assignments.sel(sel), | ||
| cluster_weights=self.cluster_weights.sel(sel), | ||
| cluster_counts=self.cluster_counts.sel(sel), | ||
| segment_durations=( | ||
| self.segment_durations.sel(sel) | ||
| if self.segment_durations is not None | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Finish the
cluster_weights→cluster_countsterminology migration. The changed code uses counts, but user-facing notebook output and a test name still expose the deprecated “weights” wording.docs/examples/getting-started.ipynb#L110-L111: rename the label and.to_dataframe()column fromweighttocountorcluster_counts.docs/examples/multi-dim.ipynb#L118-L118: rename the.to_dataframe("weight")column.test/test_parametrized.py#L302-L307: renametest_cluster_occurrences_matches_weightsto a count-oriented name.📍 Affects 3 files
docs/examples/getting-started.ipynb#L110-L111(this comment)docs/examples/multi-dim.ipynb#L118-L118test/test_parametrized.py#L302-L307🤖 Prompt for AI Agents