124124)
125125
126126if TYPE_CHECKING :
127- from cudf ._typing import ColumnLike , Dtype , NotImplementedType
127+ from cudf ._typing import (
128+ Axis ,
129+ ColumnLike ,
130+ Dtype ,
131+ NotImplementedType ,
132+ ScalarLike ,
133+ )
128134
129135_cupy_nan_methods_map = {
130136 "min" : "nanmin" ,
@@ -6517,11 +6523,11 @@ def count(self, axis=0, numeric_only=False):
65176523 @_performance_tracking
65186524 def _reduce (
65196525 self ,
6520- op ,
6526+ op : str ,
65216527 axis = None ,
6522- numeric_only = False ,
6528+ numeric_only : bool = False ,
65236529 ** kwargs ,
6524- ):
6530+ ) -> ScalarLike :
65256531 source = self
65266532
65276533 if axis is None :
@@ -6597,13 +6603,15 @@ def _reduce(
65976603 )(** kwargs )
65986604 else :
65996605 source_dtypes = [dtype for _ , dtype in source ._dtypes ]
6606+ # TODO: What happens if common_dtype is None?
66006607 common_dtype = find_common_type (source_dtypes )
66016608 if (
66026609 common_dtype == CUDF_STRING_DTYPE
66036610 and any (
66046611 dtype != CUDF_STRING_DTYPE for dtype in source_dtypes
66056612 )
6606- or common_dtype .kind != "b"
6613+ or common_dtype is not None
6614+ and common_dtype .kind != "b"
66076615 and any (dtype .kind == "b" for dtype in source_dtypes )
66086616 ):
66096617 raise TypeError (
@@ -6622,15 +6630,21 @@ def _reduce(
66226630 if res .isnull ().all ():
66236631 if cudf .api .types .is_numeric_dtype (common_dtype ):
66246632 if op in {"sum" , "product" }:
6625- if common_dtype .kind == "f" :
6633+ if (
6634+ common_dtype is not None
6635+ and common_dtype .kind == "f"
6636+ ):
66266637 res_dtype = (
66276638 np .dtype ("float64" )
66286639 if isinstance (
66296640 common_dtype , pd .ArrowDtype
66306641 )
66316642 else common_dtype
66326643 )
6633- elif common_dtype .kind == "u" :
6644+ elif (
6645+ common_dtype is not None
6646+ and common_dtype .kind == "u"
6647+ ):
66346648 res_dtype = np .dtype ("uint64" )
66356649 else :
66366650 res_dtype = np .dtype ("int64" )
@@ -6645,7 +6659,10 @@ def _reduce(
66456659 "skew" ,
66466660 "median" ,
66476661 }:
6648- if common_dtype .kind == "f" :
6662+ if (
6663+ common_dtype is not None
6664+ and common_dtype .kind == "f"
6665+ ):
66496666 res_dtype = (
66506667 np .dtype ("float64" )
66516668 if isinstance (
@@ -6668,19 +6685,22 @@ def _reduce(
66686685 @_performance_tracking
66696686 def _scan (
66706687 self ,
6671- op ,
6672- axis = None ,
6688+ op : str ,
6689+ axis : Axis | None = None ,
6690+ skipna : bool = True ,
66736691 * args ,
66746692 ** kwargs ,
6675- ):
6693+ ) -> Self :
66766694 if axis is None :
66776695 axis = 0
66786696 axis = self ._get_axis_from_axis_arg (axis )
66796697
66806698 if axis == 0 :
6681- return super ()._scan (op , axis = axis , * args , ** kwargs )
6699+ return super ()._scan (op , axis = axis , skipna = skipna , * args , ** kwargs )
66826700 elif axis == 1 :
6683- return self ._apply_cupy_method_axis_1 (op , ** kwargs )
6701+ return self ._apply_cupy_method_axis_1 (op , skipna = skipna , ** kwargs )
6702+ else :
6703+ raise ValueError (f"{ axis = } should be None, 0 or 1" )
66846704
66856705 @_performance_tracking
66866706 def mode (self , axis = 0 , numeric_only = False , dropna = True ):
@@ -6808,7 +6828,7 @@ def any(self, axis=0, bool_only=None, skipna=True, **kwargs):
68086828 return super (DataFrame , obj ).any (axis , skipna , ** kwargs )
68096829
68106830 @_performance_tracking
6811- def _apply_cupy_method_axis_1 (self , method , * args , ** kwargs ):
6831+ def _apply_cupy_method_axis_1 (self , method : str , * args , ** kwargs ):
68126832 # This method uses cupy to perform scans and reductions along rows of a
68136833 # DataFrame. Since cuDF is designed around columnar storage and
68146834 # operations, we convert DataFrames to 2D cupy arrays for these ops.
0 commit comments