Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/tsam/timeseriesaggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,9 @@ def accuracyIndicators(self):

for column in self.normalizedTimeSeries.columns:
if self.weightDict:
origTS = self.normalizedTimeSeries[column] / self.weightDict[column]
origTS = self.normalizedTimeSeries[column] / self.weightDict.get(
column, 1
)
else:
origTS = self.normalizedTimeSeries[column]
predTS = self.normalizedPredictedData[column]
Expand Down
13 changes: 13 additions & 0 deletions test/test_clustering_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,19 @@ def test_apply_to_different_columns(self, input_data):
input_data.columns
)

def test_apply_with_weights_and_extra_columns(self, input_data):
"""Test applying clustering when data has columns not in weights (GH-276)."""
# Cluster on a single column with explicit weights
wind_only = input_data[["Wind"]]
result_wind = aggregate(wind_only, n_clusters=8, weights={"Wind": 1.0})

# Apply to full data (has extra columns not in weights) - should not raise
result_full = result_wind.clustering.apply(input_data)

# Accuracy metrics should cover all columns in the applied data
assert result_full.accuracy is not None
assert len(result_full.accuracy.rmse) == len(input_data.columns)

def test_segmentation_preserved_in_transfer(self, input_data, tmp_path):
"""Test that segmentation info is preserved through JSON roundtrip."""
from tsam import ClusteringResult
Expand Down
Loading