Skip to content

Rolling with offset and axis=1 #28192

Closed
@carlr67

Description

@carlr67

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDatetimeDatetime data dtypeWindowrolling, ewma, expanding

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions