Skip to content
Merged
Changes from 1 commit
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
15 changes: 7 additions & 8 deletions pandas/core/window/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,16 @@ def _validate_get_window_bounds_signature(window: BaseIndexer) -> None:
f"get_window_bounds"
)

def _create_blocks(self, obj: FrameOrSeriesUnion):
Copy link
Contributor

Choose a reason for hiding this comment

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

can you rename these then as well, maybe _construct_data or similar

Copy link
Member Author

Choose a reason for hiding this comment

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

sure

def _create_blocks(self, obj: FrameOrSeries) -> FrameOrSeries:
"""
Split data into blocks & return conformed data.
"""
# filter out the on from the object
if self.on is not None and not isinstance(self.on, Index):
if obj.ndim == 2:
obj = obj.reindex(columns=obj.columns.difference([self.on]), copy=False)
blocks = obj._to_dict_of_blocks(copy=False).values()

return blocks, obj
return obj

def _gotitem(self, key, ndim, subset=None):
"""
Expand Down Expand Up @@ -333,7 +332,7 @@ def __repr__(self) -> str:

def __iter__(self):
window = self._get_window(win_type=None)
_, obj = self._create_blocks(self._selected_obj)
obj = self._create_blocks(self._selected_obj)
index = self._get_window_indexer(window=window)

start, end = index.get_window_bounds(
Expand Down Expand Up @@ -469,7 +468,7 @@ def _apply_series(self, homogeneous_func: Callable[..., ArrayLike]) -> "Series":
"""
Series version of _apply_blockwise
"""
_, obj = self._create_blocks(self._selected_obj)
obj = self._create_blocks(self._selected_obj)

try:
values = self._prep_values(obj.values)
Expand All @@ -489,7 +488,7 @@ def _apply_blockwise(
if self._selected_obj.ndim == 1:
return self._apply_series(homogeneous_func)

_, obj = self._create_blocks(self._selected_obj)
obj = self._create_blocks(self._selected_obj)
mgr = obj._mgr

def hfunc(bvalues: ArrayLike) -> ArrayLike:
Expand Down Expand Up @@ -1268,7 +1267,7 @@ def count(self):
# implementations shouldn't end up here
assert not isinstance(self.window, BaseIndexer)

_, obj = self._create_blocks(self._selected_obj)
obj = self._create_blocks(self._selected_obj)

def hfunc(values: np.ndarray) -> np.ndarray:
result = notna(values)
Expand Down Expand Up @@ -2234,7 +2233,7 @@ def _apply(
def _constructor(self):
return Rolling

def _create_blocks(self, obj: FrameOrSeriesUnion):
def _create_blocks(self, obj: FrameOrSeries) -> FrameOrSeries:
"""
Split data into blocks & return conformed data.
"""
Expand Down