Skip to content

Commit

Permalink
Merge branch 'master' into release/1.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
martins0n authored Jun 14, 2022
2 parents b982aa7 + 52307d2 commit 16fb8e3
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
-
-
-
-
### Fixed
-
-
Expand All @@ -61,6 +60,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Change format of holidays for holiday_plot ([#708](https://github.com/tinkoff-ai/etna/pull/708))
- Make feature selection transforms return columns in inverse_transform([#688](https://github.com/tinkoff-ai/etna/issues/688))
- Add xticks parameter for plot_periodogram, clip frequencies to be >= 1 ([#706](https://github.com/tinkoff-ai/etna/pull/706))
- Make TSDataset method to_dataset work with copy of the passed dataframe ([#741](https://github.com/tinkoff-ai/etna/pull/741))
### Fixed
- Fix bug when `ts.plot` does not save figure ([#714](https://github.com/tinkoff-ai/etna/pull/714))
- Fix bug in plot_clusters ([#675](https://github.com/tinkoff-ai/etna/pull/675))
Expand All @@ -70,6 +70,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix tiny prediction intervals ([#722](https://github.com/tinkoff-ai/etna/pull/722))
- Fix deepcopy issue for fitted deepmodel ([#735](https://github.com/tinkoff-ai/etna/pull/735))
- Fix making backtest if all segments start with NaNs ([#728](https://github.com/tinkoff-ai/etna/pull/728))
- Fix logging issues with backtest while emp intervals using ([#747](https://github.com/tinkoff-ai/etna/pull/747))

## [1.9.0] - 2022-05-17
### Added
Expand Down
17 changes: 9 additions & 8 deletions etna/datasets/tsdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,16 +657,17 @@ def to_dataset(df: pd.DataFrame) -> pd.DataFrame:
2021-01-04 3 8
2021-01-05 4 9
"""
df["timestamp"] = pd.to_datetime(df["timestamp"])
df["segment"] = df["segment"].astype(str)
feature_columns = df.columns.tolist()
df_copy = df.copy(deep=True)
df_copy["timestamp"] = pd.to_datetime(df_copy["timestamp"])
df_copy["segment"] = df_copy["segment"].astype(str)
feature_columns = df_copy.columns.tolist()
feature_columns.remove("timestamp")
feature_columns.remove("segment")
df = df.pivot(index="timestamp", columns="segment")
df = df.reorder_levels([1, 0], axis=1)
df.columns.names = ["segment", "feature"]
df = df.sort_index(axis=1, level=(0, 1))
return df
df_copy = df_copy.pivot(index="timestamp", columns="segment")
df_copy = df_copy.reorder_levels([1, 0], axis=1)
df_copy.columns.names = ["segment", "feature"]
df_copy = df_copy.sort_index(axis=1, level=(0, 1))
return df_copy

def _find_all_borders(
self,
Expand Down
3 changes: 2 additions & 1 deletion etna/pipeline/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ def _forecast_prediction_interval(
"""Add prediction intervals to the forecasts."""
if self.ts is None:
raise ValueError("Pipeline is not fitted! Fit the Pipeline before calling forecast method.")
_, forecasts, _ = self.backtest(ts=self.ts, metrics=[MAE()], n_folds=n_folds)
with tslogger.disable():
_, forecasts, _ = self.backtest(ts=self.ts, metrics=[MAE()], n_folds=n_folds)
forecasts = TSDataset(df=forecasts, freq=self.ts.freq)
residuals = (
forecasts.loc[:, pd.IndexSlice[:, "target"]]
Expand Down
8 changes: 8 additions & 0 deletions tests/test_datasets/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,3 +814,11 @@ def test_inverse_transform_back_included_columns(ts_with_features, columns, retu
ts_with_features.fit_transform([transform])
ts_with_features.inverse_transform()
assert set(original_regressors) == set(ts_with_features.regressors)


def test_to_dataset_not_modify_dataframe():
timestamp = pd.date_range("2021-01-01", "2021-02-01")
df_original = pd.DataFrame({"timestamp": timestamp, "target": 11, "segment": 1})
df_copy = df_original.copy(deep=True)
df_mod = TSDataset.to_dataset(df_original)
pd.testing.assert_frame_equal(df_original, df_copy)
32 changes: 32 additions & 0 deletions tests/test_loggers/test_file_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,38 @@ def test_local_file_logger_with_stacking_ensemble(example_df):
tslogger.remove(idx)


def test_local_file_logger_with_empirical_prediction_interval(example_df):
"""Test that LocalFileLogger correctly works in with empirical predicition intervals via backtest."""
with tempfile.TemporaryDirectory() as dirname:
cur_dir = pathlib.Path(dirname)
logger = LocalFileLogger(experiments_folder=dirname, gzip=False)

idx = tslogger.add(logger)
example_df = TSDataset.to_dataset(example_df)
example_df = TSDataset(example_df, freq="1H")
pipe = Pipeline(model=NaiveModel(), transforms=[], horizon=2)
n_folds = 5

_ = pipe.backtest(
example_df,
metrics=[MAE()],
n_jobs=4,
n_folds=n_folds,
forecast_params={"prediction_interval": True},
)

assert len(list(cur_dir.iterdir())) == 1, "we've run one experiment"

current_experiment_dir = list(cur_dir.iterdir())[0]
assert len(list(current_experiment_dir.iterdir())) == 2, "crossval and crossval_results folders"

assert (
len(list((current_experiment_dir / "crossval").iterdir())) == n_folds
), "crossval should have `n_folds` runs"

tslogger.remove(idx)


def test_s3_file_logger_fail_init_endpoint_url(monkeypatch):
"""Test that S3FileLogger can't be created without setting 'endpoint_url' environment variable."""
monkeypatch.delenv("endpoint_url", raising=False)
Expand Down

0 comments on commit 16fb8e3

Please sign in to comment.