'FutureWarning: win_type will no longer return 'freq' in a future version. Check the type of self.window instead

Sample data:

import pandas as pd
df = pd.DataFrame({'date':[pd.Timestamp('2022-03-13 16:47:29.795721'),pd.Timestamp('2022-03-13 17:03:32.313749'),pd.Timestamp('2022-03-13 17:28:56.914893'),pd.Timestamp('2022-03-13 17:45:08.242789')],'count':[5,8,2,11]})

When running this code,

df.rolling('30min', on='date')

I'm getting a baffling warning:

/usr/local/lib/python3.9/site-packages/pandas/core/window/rolling.py:287: FutureWarning: win_type will no longer return 'freq' in a future version. Check the type of self.window instead.
  if getattr(self, attr_name, None) is not None and attr_name[0] != "_"
/usr/local/lib/python3.9/site-packages/pandas/core/window/rolling.py:285: FutureWarning: win_type will no longer return 'freq' in a future version. Check the type of self.window instead.
  f"{attr_name}={getattr(self, attr_name)}"

The odd thing is that is goes away if I put it in a variable or call a method on it:

# Produces the warning
>>> df.rolling('30min', on='date')
/usr/local/lib/python3.9/site-packages/pandas/core/window/rolling.py:287: FutureWarning: win_type will no longer return 'freq' in a future version. Check the type of self.window instead.
  if getattr(self, attr_name, None) is not None and attr_name[0] != "_"
/usr/local/lib/python3.9/site-packages/pandas/core/window/rolling.py:285: FutureWarning: win_type will no longer return 'freq' in a future version. Check the type of self.window instead.
  f"{attr_name}={getattr(self, attr_name)}"
Rolling [window=30min,min_periods=1,center=False,win_type=freq,axis=0,on=date,method=single]

# Doesn't produce the warning
>>> rolling = df.rolling('30min', on='date')
>>> rolling
Rolling [window=30min,min_periods=1,center=False,win_type=freq,axis=0,on=date,method=single]

# Doesn't produce the warning
>>> df.rolling('30min', on='date')['count'].sum()
0     5.0
1    13.0
2    10.0
3    13.0
Name: count, dtype: float64

What's causing this warning? Is there something I should fix in my code?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source