Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rolling with offset and axis=1 #28192

Closed
carlr67 opened this issue Aug 28, 2019 · 3 comments · Fixed by #28267
Closed

Rolling with offset and axis=1 #28192

carlr67 opened this issue Aug 28, 2019 · 3 comments · Fixed by #28267
Labels
Bug Timeseries Window rolling, ewma, expanding
Milestone

Comments

@carlr67
Copy link

carlr67 commented Aug 28, 2019

Code Sample

Here I have a DataFrame with a DatetimeIndex for the columns:

cols = pd.date_range('2019-8-01', '2019-08-07', freq='D')
data = np.ones((5, len(cols)))
df = pd.DataFrame(data, columns=cols)
df.rolling('1d', axis=1).sum()

The above gives 'ValueError: window must be an integer'

Here I have a DataFrame with a DatetimeIndex for the rows:

df2 = df.transpose()
df2.rolling('2d', axis=0).sum()

However this works totally fine.

Problem description

I believe there may be a bug: If I have a DatetimeIndex in the columns, specifying an offset for df.rolling does not work but gives a value error (that the window must be an integer). It works however as expected if I transpose the dataframe.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.7.4.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None

pandas : 0.25.1
numpy : 1.16.4
pytz : 2019.2
dateutil : 2.8.0
pip : 19.2.2
setuptools : 41.0.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10.1
IPython : 7.7.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.1.0
numexpr : None
odfpy : None
openpyxl : 2.6.2
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : 1.3.1
sqlalchemy : None
tables : None
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : None

@WillAyd
Copy link
Member

WillAyd commented Aug 28, 2019

Our support for rolling across axis=1 is less tested and feature complete than axis=0 so not terribly surprising. If you'd like to investigate and submit a PR would certainly be welcome

@WillAyd WillAyd added Bug Window rolling, ewma, expanding Timeseries labels Aug 28, 2019
@MarcoGorelli
Copy link
Member

MarcoGorelli commented Sep 3, 2019

In your example with axis=0, then in Rolling.validate from pandas/core/windows/rolling.py, self.is_datetimelike returns True, while for axis=1 it returns False. If you're not working on this, I'd be interested in giving it a go

@carlr67
Copy link
Author

carlr67 commented Sep 3, 2019

Thanks for finding that out. Sure, feel free to give it a go!

@jreback jreback added this to the 1.0 milestone Sep 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Timeseries Window rolling, ewma, expanding
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants