Skip to content

CLN: window/rolling.py #35982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 31, 2020
Merged
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
23 changes: 6 additions & 17 deletions pandas/core/window/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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:
Copy link
Member

Choose a reason for hiding this comment

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

ATM _prep_values prevents us from doing anything with EAs, but in principle is that something we'd like to support?

Copy link
Member Author

Choose a reason for hiding this comment

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

In the future yes, but I think a major blocker/consideration is that today rolling agg functions only operate on float64 inputs, so that will need to be addressed in tandem.

"""
Center the result in the window.
"""
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down