Skip to content

[BUG] DifferencingTransform inverse transform bug #499

Closed
1 task done
martins0n opened this issue Feb 4, 2022 · 0 comments · Fixed by #503
Closed
1 task done

[BUG] DifferencingTransform inverse transform bug #499

martins0n opened this issue Feb 4, 2022 · 0 comments · Fixed by #503
Assignees
Labels
bug Something isn't working

Comments

@martins0n
Copy link
Contributor

🐛 Bug Report

It seems DifferencingTransfrom doesn's handle df with multiple features.

For exampe in case below, I have error. But if i'd swapped LagTransform and DifferencingTransform -- the error would not have occurred

Expected behavior

It seems should work

How To Reproduce

from etna.datasets import generate_ar_df

tss = TSDataset(TSDataset.to_dataset(generate_ar_df(300, "2021-02-01", n_segments=20)), freq="1D")

linear_pipeline = Pipeline(
    model=LinearPerSegmentModel(), 
    transforms=[
        TimeSeriesImputerTransform(),
        LagTransform(in_column="target", lags=list(range(30, 100, 5))),
        HolidayTransform(),
        DifferencingTransform("target"),
        DateFlagsTransform(week_number_in_month=True, week_number_in_year=True, month_number_in_year=True),
        SegmentEncoderTransform()
    ], 
    horizon=24
)
metrics, forecast, info = linear_pipeline.backtest(tss, [MAE()], n_jobs=5)

Trace:

---------------------------------------------------------------------------
RemoteTraceback                           Traceback (most recent call last)
RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/home/marti/.pyenv/versions/3.8.6/lib/python3.8/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/home/marti/.pyenv/versions/3.8.6/lib/python3.8/site-packages/joblib/_parallel_backends.py", line 595, in __call__
    return self.func(*args, **kwargs)
  File "/home/marti/.pyenv/versions/3.8.6/lib/python3.8/site-packages/joblib/parallel.py", line 262, in __call__
    return [func(*args, **kwargs)
  File "/home/marti/.pyenv/versions/3.8.6/lib/python3.8/site-packages/joblib/parallel.py", line 262, in <listcomp>
    return [func(*args, **kwargs)
  File "/home/marti/.pyenv/versions/3.8.6/lib/python3.8/site-packages/etna/pipeline/pipeline.py", line 257, in _run_fold
    forecast = pipeline.forecast()
  File "/home/marti/.pyenv/versions/3.8.6/lib/python3.8/site-packages/etna/pipeline/pipeline.py", line 163, in forecast
    predictions = self.model.forecast(ts=future)
  File "/home/marti/.pyenv/versions/3.8.6/lib/python3.8/site-packages/etna/models/base.py", line 25, in wrapper
    result = f(self, *args, **kwargs)
  File "/home/marti/.pyenv/versions/3.8.6/lib/python3.8/site-packages/etna/models/base.py", line 141, in forecast
    ts.inverse_transform()
  File "/home/marti/.pyenv/versions/3.8.6/lib/python3.8/site-packages/etna/datasets/tsdataset.py", line 279, in inverse_transform
    self.df = transform.inverse_transform(self.df)
  File "/home/marti/.pyenv/versions/3.8.6/lib/python3.8/site-packages/etna/transforms/math/differencing.py", line 369, in inverse_transform
    result_df = transform.inverse_transform(result_df)
  File "/home/marti/.pyenv/versions/3.8.6/lib/python3.8/site-packages/etna/transforms/math/differencing.py", line 226, in inverse_transform
    result_df = self._reconstruct_test(df, columns_to_inverse)
  File "/home/marti/.pyenv/versions/3.8.6/lib/python3.8/site-packages/etna/transforms/math/differencing.py", line 181, in _reconstruct_test
    init_df.columns.set_levels([column], level="feature", inplace=True)
  File "/home/marti/.pyenv/versions/3.8.6/lib/python3.8/site-packages/pandas/util/_decorators.py", line 311, in wrapper
    return func(*args, **kwargs)
  File "/home/marti/.pyenv/versions/3.8.6/lib/python3.8/site-packages/pandas/core/indexes/multi.py", line 912, in set_levels
    idx._set_levels(
  File "/home/marti/.pyenv/versions/3.8.6/lib/python3.8/site-packages/pandas/core/indexes/multi.py", line 795, in _set_levels
    new_codes = self._verify_integrity(levels=new_levels)
  File "/home/marti/.pyenv/versions/3.8.6/lib/python3.8/site-packages/pandas/core/indexes/multi.py", line 410, in _verify_integrity
    raise ValueError(
ValueError: On level 1, code max (15) >= length of level (1). NOTE: this index is in an inconsistent state

Environment

No response

Additional context

No response

Checklist

  • Bug appears at the latest library version
@martins0n martins0n added the bug Something isn't working label Feb 4, 2022
@martins0n martins0n moved this to Specification in etna board Feb 4, 2022
@Mr-Geekman Mr-Geekman self-assigned this Feb 4, 2022
@Mr-Geekman Mr-Geekman moved this from Specification to In Review in etna board Feb 4, 2022
Repository owner moved this from In Review to Done in etna board Feb 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
Status: Done
2 participants