Skip to content

Commit

Permalink
fix: optimize mapping from timestamps to indices
Browse files Browse the repository at this point in the history
  • Loading branch information
d.a.bunin committed Jun 22, 2023
1 parent 996dd49 commit c25d1fa
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions etna/transforms/missing_values/imputation.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@ def _fill(self, df: pd.DataFrame) -> pd.DataFrame:
for segment in segments:
df.loc[:, pd.IndexSlice[segment, self.in_column]].fillna(value=self._fill_value[segment], inplace=True)
elif self._strategy is ImputerMode.running_mean or self._strategy is ImputerMode.seasonal:
timestamp_to_index = {timestamp: i for i, timestamp in enumerate(df.index)}
for segment in segments:
history = self.seasonality * self.window if self.window != -1 else len(df)
timestamps = list(df.index)
for timestamp in self._nan_timestamps[segment]:
i = timestamps.index(timestamp)
i = timestamp_to_index[timestamp]
indexes = np.arange(i - self.seasonality, i - self.seasonality - history, -self.seasonality)
indexes = indexes[indexes >= 0]
values = df.loc[df.index[indexes], pd.IndexSlice[segment, self.in_column]]
Expand Down

0 comments on commit c25d1fa

Please sign in to comment.