Skip to content

Unable to perform seasonal decomposition in latest release of statsmodels #3225

Closed

Description

@virsto

The following code fails

    import numpy as np   # Version: 1.11.2+mk
    import pandas as pd  # Version: 0.19.0
    import statsmodels.api as sm  # statsmodels-0.8.0rc1-cp27-cp27m-win32.whl

    dateparse = lambda dates: pd.datetime.strptime(dates, '%Y-%m')
    # Get AirPassengers.csv from: https://www.analyticsvidhya.com/wp-content/uploads/2016/02/AirPassengers.csv
    data = pd.read_csv('AirPassengers.csv', parse_dates=[0], dayfirst=False, date_parser=dateparse)

    ts = data["#Passengers"] 

    decomposition = sm.tsa.seasonal_decompose(ts)

Gives error:
AttributeError: 'RangeIndex' object has no attribute 'inferred_freq'
File "d:\PythonCode\statsmodels_Test_02.py", line 11, in
decomposition = sm.tsa.seasonal_decompose(ts)
File "C:\Python27\Lib\site-packages\statsmodels\tsa\seasonal.py", line 68, in seasonal_decompose
_pandas_wrapper, pfreq = _maybe_get_pandas_wrapper_freq(x)
File "C:\Python27\Lib\site-packages\statsmodels\tsa\filters_utils.py", line 46, in _maybe_get_pandas_wrapper_freq
freq = index.inferred_freq

How to fix this?

Activity

  1. josef-pkt commented on Oct 5, 2016

    @josef-pkt
    Member

    In 0.8, you should be able to specify freq as keyword argument to override the index.
    Without that there is no way to infer the length of a season if the index is not a datetime index with the freq information.

  2. virsto commented on Oct 6, 2016

    @virsto
    Author

    Thanks josef-pkt for your prompt response to my problem. I have been working on my code and looking into the module(s) that are involved in the generation of this error. However, I have yet to find a solution. Perhaps you could elaborate on how to force (or over ride the index) to make it a datetime index with freq information. Or if you have a simple example or if you have a link to code that illustrates your suggestion. Best :-)

  3. reopened this on Oct 6, 2016
  4. virsto commented on Oct 6, 2016

    @virsto
    Author

    One suggestion --- a more informative error message would be helpful.

  5. bashtage commented on Jul 22, 2019

    @bashtage
    Member

    This works as expected now, and provides a useful error message. Closing.

  6. added this to the 0.11 milestone on Dec 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions