diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index 39fcfcbe2bff6..05cc996178051 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -377,23 +377,13 @@ def _prep_values(self, values: Optional[np.ndarray] = None) -> np.ndarray: return values - def _wrap_result(self, result, block=None, obj=None): + def _wrap_result(self, result: np.ndarray) -> "Series": """ - Wrap a single result. + Wrap a single 1D result. """ - if obj is None: - obj = self._selected_obj - index = obj.index + obj = self._selected_obj - if isinstance(result, np.ndarray): - - if result.ndim == 1: - from pandas import Series - - return Series(result, index, name=obj.name) - - return type(obj)(result, index=index, columns=block.columns) - return result + return obj._constructor(result, obj.index, name=obj.name) def _wrap_results(self, results, obj, skipped: List[int]) -> FrameOrSeriesUnion: """ @@ -454,7 +444,7 @@ def _insert_on_column(self, result: "DataFrame", obj: "DataFrame"): # insert at the end result[name] = extra_col - def _center_window(self, result, window) -> np.ndarray: + def _center_window(self, result: np.ndarray, window) -> np.ndarray: """ Center the result in the window. """ @@ -513,7 +503,6 @@ def _apply_series(self, homogeneous_func: Callable[..., ArrayLike]) -> "Series": Series version of _apply_blockwise """ _, obj = self._create_blocks(self._selected_obj) - values = obj.values try: values = self._prep_values(obj.values) @@ -535,7 +524,7 @@ def _apply_blockwise( # This isn't quite blockwise, since `blocks` is actually a collection # of homogenenous DataFrames. - blocks, obj = self._create_blocks(self._selected_obj) + _, obj = self._create_blocks(self._selected_obj) mgr = obj._mgr def hfunc(bvalues: ArrayLike) -> ArrayLike: