Skip to content

Commit 6229499

Browse files
committed
BUG: GH11697 where memory allocation erroneously failed in rolling_median
1 parent 0c43fcc commit 6229499

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

doc/source/whatsnew/v0.18.0.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,4 @@ Bug Fixes
190190

191191

192192
- Bug in ``.loc`` result with duplicated key may have ``Index`` with incorrect dtype (:issue:`11497`)
193+
- Bug in ``pd.rolling_median`` where memory allocation failed even with sufficient memory (:issue:`11696`)

pandas/src/skiplist.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ typedef struct {
6060
} skiplist_t;
6161

6262
static PANDAS_INLINE double urand(void) {
63-
return rand() / ((double) RAND_MAX + 1);
63+
return ((double) rand() + 1) / ((double) RAND_MAX + 2);
6464
}
6565

6666
static PANDAS_INLINE int int_min(int a, int b) {

pandas/stats/tests/test_moments.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,6 +1919,12 @@ def test_rolling_median_how_resample(self):
19191919
x = mom.rolling_median(series, window=1, freq='D')
19201920
assert_series_equal(expected, x)
19211921

1922+
def test_rolling_median_memory_error(self):
1923+
# GH11722
1924+
n = 20000
1925+
mom.rolling_median(Series(np.random.randn(n)), window=2, center=False)
1926+
mom.rolling_median(Series(np.random.randn(n)), window=2, center=False)
1927+
19221928
if __name__ == '__main__':
19231929
import nose
19241930
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],

0 commit comments

Comments
 (0)