Skip to content

Commit b27d7e4

Browse files
committed
WIP
1 parent d0b6962 commit b27d7e4

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

pandas/core/window/rolling.py

+23-15
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,19 @@ def _slice_axis_for_step(self, index: Index, result: Sized | None = None) -> Ind
259259
else index[:: self.step]
260260
)
261261

262-
def _numeric_only(self, obj: NDFrameT, numeric_only: bool):
263-
if numeric_only:
264-
obj = obj.select_dtypes(include=["number"], exclude=["timedelta"])
265-
return obj
262+
def _make_numeric_only(self, obj: NDFrameT) -> NDFrameT:
263+
"""Subset DataFrame to numeric columns.
264+
265+
Parameters
266+
----------
267+
obj : DataFrame
268+
269+
Returns
270+
-------
271+
obj subset to numeric-only columns.
272+
"""
273+
result = obj.select_dtypes(include=["number"], exclude=["timedelta"])
274+
return result
266275

267276
def _create_data(self, obj: NDFrameT, numeric_only: bool = False) -> NDFrameT:
268277
"""
@@ -272,13 +281,13 @@ def _create_data(self, obj: NDFrameT, numeric_only: bool = False) -> NDFrameT:
272281
if self.on is not None and not isinstance(self.on, Index) and obj.ndim == 2:
273282
obj = obj.reindex(columns=obj.columns.difference([self.on]), copy=False)
274283
if numeric_only or self.axis == 1:
275-
obj = obj.select_dtypes(include=["number"], exclude=["timedelta"])
276-
if self.axis == 1:
277-
# GH: 20649 in case of mixed dtype and axis=1 we have to convert
278-
# everything to float to calculate the complete row at once. We
279-
# exclude all non-numeric dtypes.
280-
obj = obj.astype("float64", copy=False)
281-
obj._mgr = obj._mgr.consolidate()
284+
# GH: 20649 in case of mixed dtype and axis=1 we have to convert everything
285+
# to float to calculate the complete row at once. We exclude all non-numeric
286+
# dtypes.
287+
obj = self._make_numeric_only(obj)
288+
if self.axis == 1:
289+
obj = obj.astype("float64", copy=False)
290+
obj._mgr = obj._mgr.consolidate()
282291
return obj
283292

284293
def _gotitem(self, key, ndim, subset=None):
@@ -566,8 +575,8 @@ def _apply_pairwise(
566575
pairwise = True if pairwise is None else pairwise
567576
elif not isinstance(other, (ABCDataFrame, ABCSeries)):
568577
raise ValueError("other must be a DataFrame or Series")
569-
elif other.ndim == 2:
570-
other = self._numeric_only(other, numeric_only)
578+
elif other.ndim == 2 and numeric_only:
579+
other = self._make_numeric_only(other)
571580

572581
return flex_binary_moment(target, other, func, pairwise=bool(pairwise))
573582

@@ -2379,8 +2388,7 @@ def var(
23792388
aggregation_description="unbiased skewness",
23802389
agg_method="skew",
23812390
)
2382-
def skew(self, numeric_only: bool = False, *args, **kwargs):
2383-
nv.validate_rolling_func("skew", args, kwargs)
2391+
def skew(self, numeric_only: bool = False, **kwargs):
23842392
return super().skew(numeric_only=numeric_only, **kwargs)
23852393

23862394
@doc(

0 commit comments

Comments
 (0)