Skip to content
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

Small improvements to timeseriesaggregation #82

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 6 additions & 7 deletions tsam/timeseriesaggregation.py
Expand Up @@ -8,7 +8,6 @@
import numpy as np

from sklearn.metrics import mean_squared_error, mean_absolute_error
from sklearn.metrics.pairwise import euclidean_distances
from sklearn import preprocessing

from tsam.periodAggregation import aggregatePeriods
Expand Down Expand Up @@ -388,21 +387,21 @@ def _check_init_args(self):
try:
timedelta = self.timeSeries.index[1] - self.timeSeries.index[0]
self.resolution = float(timedelta.total_seconds()) / 3600
except AttributeError:
except AttributeError as exc:
raise ValueError(
"'resolution' argument has to be nonnegative float or int"
+ " or the given timeseries needs a datetime index"
)
) from exc
except TypeError:
try:
self.timeSeries.index = pd.to_datetime(self.timeSeries.index)
timedelta = self.timeSeries.index[1] - self.timeSeries.index[0]
self.resolution = float(timedelta.total_seconds()) / 3600
except:
except Exception as exc:
raise ValueError(
"'resolution' argument has to be nonnegative float or int"
+ " or the given timeseries needs a datetime index"
)
) from exc

if not (isinstance(self.resolution, int) or isinstance(self.resolution, float)):
raise ValueError("resolution has to be nonnegative float or int")
Expand Down Expand Up @@ -870,9 +869,9 @@ def _rescaleClusterPeriods(self, clusterOrder, clusterPeriods, extremeClusterIdx
)

# reset values higher than the upper sacle or less than zero
typicalPeriods[column].clip(lower=0, upper=scale_ub, inplace=True)
typicalPeriods[column] = typicalPeriods[column].clip(lower=0, upper=scale_ub)

typicalPeriods[column].fillna(0.0, inplace=True)
typicalPeriods[column] = typicalPeriods[column].fillna(0.0)

# calc new sum and new diff to orig data
sum_clu_wo_peak = np.sum(
Expand Down