Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ Groupby/resample/rolling
- Bug in :meth:`GroupBy.cummax` with ``int64`` dtype with leading value being the smallest possible int64 (:issue:`46382`)
- Bug in :meth:`GroupBy.max` with empty groups and ``uint64`` dtype incorrectly raising ``RuntimeError`` (:issue:`46408`)
- Bug in :meth:`.GroupBy.apply` would fail when ``func`` was a string and args or kwargs were supplied (:issue:`46479`)
-
- Bug in :meth:`.Rolling.var` would segfault calculating weighted variance when window size was larger than data size (:issue:`46760`)

Reshaping
^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/window/aggregations.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,7 @@ def roll_weighted_var(const float64_t[:] values, const float64_t[:] weights,

with nogil:

for i in range(win_n):
for i in range(min(win_n, n)):
add_weighted_var(values[i], weights[i], &t,
&sum_w, &mean, &nobs)

Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/window/test_win_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,3 +676,13 @@ def test_cmov_window_special_linear_range(win_types_special, step):
.mean(**kwds[win_types_special])
)
tm.assert_series_equal(xp, rs)


@td.skip_if_no_scipy
def test_weighted_var_big_window_no_segfault(win_types, center):
# Github Issue #46772
x = Series(0)
result = x.rolling(window=16, center=center, win_type=win_types).var()
expected = Series(np.NaN)

tm.assert_series_equal(result, expected)