Skip to content

Commit 53f4ac1

Browse files
committed
Updates based on comments
1 parent e1eb836 commit 53f4ac1

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

doc/source/whatsnew/v1.3.4.rst

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Fixed regressions
2323

2424
Bug fixes
2525
~~~~~~~~~
26+
- Bug in :meth:`pandas.DataFrame.groupby.rolling` and :class:`pandas.api.indexers.FixedForwardWindowIndexer` leading to segfaults and window endpoints being mixed across groups (:issue:`43267`)
2627
-
2728
-
2829

pandas/core/indexers/objects.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,7 @@ def get_window_bounds(
342342
)
343343
start = start.astype(np.int64)
344344
end = end.astype(np.int64)
345-
# From get_window_bounds, those two should be equal in length of array
346-
assert len(start) == len(end)
345+
assert len(start) == len(end), 'these should be equal in length from get_window_bounds'
347346
# Cannot use groupby_indices as they might not be monotonic with the object
348347
# we're rolling over
349348
window_indices = np.arange(
@@ -352,7 +351,7 @@ def get_window_bounds(
352351
window_indices_start += len(indices)
353352
# Extend as we'll be slicing window like [start, end)
354353
window_indices = np.append(window_indices, [window_indices[-1] + 1]).astype(
355-
np.int64
354+
np.int64, copy=False
356355
)
357356
start_arrays.append(window_indices.take(ensure_platform_int(start)))
358357
end_arrays.append(window_indices.take(ensure_platform_int(end)))

pandas/core/window/rolling.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,7 @@ def __iter__(self):
301301
closed=self.closed,
302302
)
303303

304-
# From get_window_bounds, those two should be equal in length of array
305-
assert len(start) == len(end)
304+
assert len(start) == len(end), 'these should be equal in length from get_window_bounds'
306305

307306
for s, e in zip(start, end):
308307
result = obj.iloc[slice(s, e)]
@@ -555,9 +554,8 @@ def calc(x):
555554
center=self.center,
556555
closed=self.closed,
557556
)
557+
assert len(start) == len(end), 'these should be equal in length from get_window_bounds'
558558

559-
# From get_window_bounds, those two should be equal in length of array
560-
assert len(start) == len(end)
561559
return func(x, start, end, min_periods, *numba_args)
562560

563561
with np.errstate(all="ignore"):
@@ -1441,8 +1439,7 @@ def cov_func(x, y):
14411439
closed=self.closed,
14421440
)
14431441

1444-
# From get_window_bounds, those two should be equal in length of array
1445-
assert len(start) == len(end)
1442+
assert len(start) == len(end), 'these should be equal in length from get_window_bounds'
14461443

14471444
with np.errstate(all="ignore"):
14481445
mean_x_y = window_aggregations.roll_mean(
@@ -1484,8 +1481,7 @@ def corr_func(x, y):
14841481
closed=self.closed,
14851482
)
14861483

1487-
# From get_window_bounds, those two should be equal in length of array
1488-
assert len(start) == len(end)
1484+
assert len(start) == len(end), 'these should be equal in length from get_window_bounds'
14891485

14901486
with np.errstate(all="ignore"):
14911487
mean_x_y = window_aggregations.roll_mean(

0 commit comments

Comments
 (0)