Skip to content

Commit

Permalink
BUG: Fix error when window size > array size in rolling_apply. close #…
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Sep 8, 2012
1 parent 7eaf5ca commit cd9655c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ pandas 0.8.2
- Let Series.str.split accept no arguments (like str.split) (#1859)
- Allow user to have dateutil 2.1 installed on a Python 2 system (#1851)
- Catch ImportError less aggressively in pandas/__init__.py (#1845)
- Fix pip source installation bug when installing from GitHub (#1805)
- Fix error when window size > array size in rolling_apply (#1850) - Fix pip source installation issues via SSH from GitHub

This comment has been minimized.

Copy link
@mrjbq7

mrjbq7 Sep 8, 2012

Awesome, thanks! Btw, noticed the RELEASE notes might have duplicated the "fix pip source installation" line.

This comment has been minimized.

Copy link
@mrjbq7

mrjbq7 Sep 8, 2012

Nevermind, I see you fixed it just now!


pandas 0.8.1
============
Expand Down
2 changes: 1 addition & 1 deletion pandas/src/moments.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ def roll_generic(ndarray[float64_t, cast=True] input, int win,
oldbuf = <float64_t*> bufarr.data

n = len(input)
for i from 0 <= i < win:
for i from 0 <= i < int_min(win, n):
if counts[i] >= minp:
output[i] = func(input[int_max(i - win + 1, 0) : i + 1])
else:
Expand Down
11 changes: 11 additions & 0 deletions pandas/stats/tests/test_moments.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ def roll_mean(x, window, min_periods=None, freq=None):
freq=freq)
self._check_moment_func(roll_mean, np.mean)

def test_rolling_apply_out_of_bounds(self):
# #1850
arr = np.arange(4)

# it works!
result = mom.rolling_apply(arr, 10, np.sum)
self.assert_(isnull(result).all())

result = mom.rolling_apply(arr, 10, np.sum, min_periods=1)
assert_almost_equal(result, result)

def test_rolling_std(self):
self._check_moment_func(mom.rolling_std,
lambda x: np.std(x, ddof=1))
Expand Down

3 comments on commit cd9655c

@sivananth
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, this issue seems to be affecting rolling_std and rolling_var also (at least, rolling_mean seems to be okay). Can you please check?

@jreback
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a 3-year old issue you are commenting. Pls open a new issue with a minimally reproducible example as well as pd.show_versions()

@sivananth
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright, thank you

Please sign in to comment.