question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: Offset-based rolling window, with closed='left' and max as aggregation function, make python crash

See original GitHub issue

Code Sample, a copy-pastable example if possible

import pandas as pd
import numpy as np
from pandas.tseries.frequencies import to_offset

df = pd.Series(data=np.arange(10), 
               index=pd.date_range('2000', periods=10))

df.rolling(to_offset('3D'), closed='left').max()

Problem description

With this rolling and aggregation function, python just crashes. It does too with .min() or .agg(np.max) as aggregation steps. It does not when closed='right' or with mean as an aggregation function.

Expected Output

2000-01-01    NaN
2000-01-02    0.0
2000-01-03    1.0
2000-01-04    2.0
2000-01-05    3.0
2000-01-06    4.0
2000-01-07    5.0
2000-01-08    6.0
2000-01-09    7.0
2000-01-10    8.0
Freq: D, dtype: float64

or, if closed='left' raises complicated problems (as it is not implemented for fixed windows), disable it too for the offset-based windows.

Output of pd.show_versions()

INSTALLED VERSIONS

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

pandas: 0.23.1 pytest: 3.2.1 pip: 10.0.1 setuptools: 36.5.0.post20170921 Cython: 0.26.1 numpy: 1.12.1 scipy: 0.19.1 pyarrow: None xarray: None IPython: 6.1.0 sphinx: 1.6.3 patsy: 0.4.1 dateutil: 2.6.1 pytz: 2017.2 blosc: None bottleneck: 1.2.1 tables: 3.4.2 numexpr: 2.6.2 feather: None matplotlib: 2.1.0 openpyxl: 2.4.8 xlrd: 1.1.0 xlwt: 1.3.0 xlsxwriter: 1.0.2 lxml: 4.1.0 bs4: 4.5.3 html5lib: 0.9999999 sqlalchemy: 1.1.13 pymysql: None psycopg2: 2.7.3.2 (dt dec pq3 ext lo64) jinja2: 2.10 s3fs: None fastparquet: None pandas_gbq: None pandas_datareader: None

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
uds5501commented, Jul 2, 2018

The bug exists on master branch.

1reaction
changhiskhancommented, Jul 11, 2018

I just hit this as well. @JacquotLeHaricot you’re intuition was spot on. Definitely an off-by-one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I use pandas rolling function without aggregated ...
I want to use rolling function in pandas, but I don't need the aggregated function (sum, mean, min, max,...) after rolling.
Read more >
pandas.core.window.rolling.Rolling.aggregate
Function to use for aggregating the data. If a function, must either work when passed a Series/Dataframe or when passed to Series/Dataframe.apply.
Read more >
CrashingPython - Python Wiki
I'm saying that if you crash it, it's a bug unless proven harebrained. ... The following code is known to crashing python 2.4.3...
Read more >
Window Functions in Python
The Windows function is also known in SQL for its ability to aggregate or group rows of data in a particular way which...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found