ValueError You Must Pass a Freq Argument as Current Index has None

Sometimes, you get ValueError You must pass a freq argument as current index has none error when you are working with the PyCaret module and trying to set up the module for the time series dataset. I was having the same problem and after doing some research I came to know the reason. For PayCaret, we need to convert our time series data into Series and then assigned the date as index values. In this article, we will explore the error more clearly and will go through various solutions as well.

ValueError: You Must Pass a Freq Argument as Current Index has None

If you have any questions or suggestions, please let us know through comments.

Solve ValueError You must pass a freq argument as current index has none

When you are working with PyCaret module and trying to set up the module for the time series dataset, you might face this issue. The main reason for getting this error is the format of the dataset. Mostly, we use a Pandas data frame in order to set up the module but we end up having ValueError: You must pass a freq argument as current index has none error.

The error can be solved by converting the data frame into pandas series and assigning the date and index value to the data.

Let us first see, why we are getting the error. We will import PayCaret and the dataset and try to implement the time series models.

from pycaret import *
pm1.set_index('Day')

Output:

ValueError-You-Must-Pass-a-Freq-Argument-as-Current-Index-has-None

If we will use this dataset to set up, then we will get an error because this data does not have indexed by date.

# import pycaret time series and init setup
from pycaret.time_series import *
s = setup(pm1, fh = 3, session_id = 123)

This will raise the error, ValueError: You Must Pass a Freq Argument as Current Index has None.

Solution: Changing the Data Format

For now, our data is in the form of Pandas Data Frame and we need to change the data from Data Frame into a pandas series and fix the index by date as shown below:

# getting only output values
p = pm1['PM1(mcg/m³)']

# converting the date into list
d =list(pm1['Day'])

# indeing with date
p.index = d

print(type(p))
print(p)

Output:

<class 'pandas.core.series.Series'>
2021-06-20    6.26
2021-06-21    5.61
2021-06-22    6.38
2021-06-23    6.43
2021-06-24    5.66
              ... 
2022-08-28    6.20
2022-08-29    5.39
2022-08-30    5.11
2022-08-31    5.58
2022-09-01    5.63
Name: PM1(mcg/m³), Length: 439, dtype: float64

As you can see, now our data is in the form of a Series with the date as index values. Now, we can easily apply the PyCaret and evaluate the dataset.

# import pycaret time series and init setup
from pycaret.time_series import *
s = setup(p, fh = 3, session_id = 123)

Now the code will run without giving any errors.

Reasons for getting ValueError You Must Pass a Freq Argument as Current Index has None

As we have already discussed the main reason for getting the error which is the incorrect formatting of the dataset. However, there can be many other possible reasons as well for getting the error which we will go through here.

  • The time index might be missing or incomplete in the time series dataset, so better to check the dataset first before applying the model.
  • The time series data might have incorrect or inconsistent frequency so better to go through the time series as well.
  • Another reason might be the data format issue. Make sure that you have converted the date column into the proper data format.
  • The date column might have missing or NaN values which makes it again inconsistent so make sure to handle the null values as well.

Summary

The reason for getting the error is because of incorrect data formatting and the error can be easily solved by changing the format of the data as we did in the above section. In this short article, we discussed how we can solve the problem and we listed some of the main reasons for getting the error

Leave a Comment