@@ -259,10 +259,19 @@ def _slice_axis_for_step(self, index: Index, result: Sized | None = None) -> Ind
259
259
else index [:: self .step ]
260
260
)
261
261
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
266
275
267
276
def _create_data (self , obj : NDFrameT , numeric_only : bool = False ) -> NDFrameT :
268
277
"""
@@ -272,13 +281,13 @@ def _create_data(self, obj: NDFrameT, numeric_only: bool = False) -> NDFrameT:
272
281
if self .on is not None and not isinstance (self .on , Index ) and obj .ndim == 2 :
273
282
obj = obj .reindex (columns = obj .columns .difference ([self .on ]), copy = False )
274
283
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 ()
282
291
return obj
283
292
284
293
def _gotitem (self , key , ndim , subset = None ):
@@ -566,8 +575,8 @@ def _apply_pairwise(
566
575
pairwise = True if pairwise is None else pairwise
567
576
elif not isinstance (other , (ABCDataFrame , ABCSeries )):
568
577
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 )
571
580
572
581
return flex_binary_moment (target , other , func , pairwise = bool (pairwise ))
573
582
@@ -2379,8 +2388,7 @@ def var(
2379
2388
aggregation_description = "unbiased skewness" ,
2380
2389
agg_method = "skew" ,
2381
2390
)
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 ):
2384
2392
return super ().skew (numeric_only = numeric_only , ** kwargs )
2385
2393
2386
2394
@doc (
0 commit comments