@@ -11137,12 +11137,13 @@ def any( # type: ignore[override]
11137
11137
bool_only : bool = False ,
11138
11138
skipna : bool = True ,
11139
11139
** kwargs ,
11140
- ) -> Series :
11141
- # error: Incompatible return value type (got "Union[Series, bool]",
11142
- # expected "Series")
11143
- return self ._logical_func ( # type: ignore[return-value]
11140
+ ) -> Series | bool :
11141
+ result = self ._logical_func (
11144
11142
"any" , nanops .nanany , axis , bool_only , skipna , ** kwargs
11145
11143
)
11144
+ if isinstance (result , Series ):
11145
+ result = result .__finalize__ (self , method = "any" )
11146
+ return result
11146
11147
11147
11148
@doc (make_doc ("all" , ndim = 2 ))
11148
11149
def all (
@@ -11151,12 +11152,13 @@ def all(
11151
11152
bool_only : bool = False ,
11152
11153
skipna : bool = True ,
11153
11154
** kwargs ,
11154
- ) -> Series :
11155
- # error: Incompatible return value type (got "Union[Series, bool]",
11156
- # expected "Series")
11157
- return self ._logical_func ( # type: ignore[return-value]
11155
+ ) -> Series | bool :
11156
+ result = self ._logical_func (
11158
11157
"all" , nanops .nanall , axis , bool_only , skipna , ** kwargs
11159
11158
)
11159
+ if isinstance (result , Series ):
11160
+ result = result .__finalize__ (self , method = "all" )
11161
+ return result
11160
11162
11161
11163
@doc (make_doc ("min" , ndim = 2 ))
11162
11164
def min (
@@ -11166,7 +11168,10 @@ def min(
11166
11168
numeric_only : bool = False ,
11167
11169
** kwargs ,
11168
11170
):
11169
- return super ().min (axis , skipna , numeric_only , ** kwargs )
11171
+ result = super ().min (axis , skipna , numeric_only , ** kwargs )
11172
+ if isinstance (result , Series ):
11173
+ result = result .__finalize__ (self , method = "min" )
11174
+ return result
11170
11175
11171
11176
@doc (make_doc ("max" , ndim = 2 ))
11172
11177
def max (
@@ -11176,7 +11181,10 @@ def max(
11176
11181
numeric_only : bool = False ,
11177
11182
** kwargs ,
11178
11183
):
11179
- return super ().max (axis , skipna , numeric_only , ** kwargs )
11184
+ result = super ().max (axis , skipna , numeric_only , ** kwargs )
11185
+ if isinstance (result , Series ):
11186
+ result = result .__finalize__ (self , method = "max" )
11187
+ return result
11180
11188
11181
11189
@doc (make_doc ("sum" , ndim = 2 ))
11182
11190
def sum (
@@ -11199,7 +11207,8 @@ def prod(
11199
11207
min_count : int = 0 ,
11200
11208
** kwargs ,
11201
11209
):
11202
- return super ().prod (axis , skipna , numeric_only , min_count , ** kwargs )
11210
+ result = super ().prod (axis , skipna , numeric_only , min_count , ** kwargs )
11211
+ return result .__finalize__ (self , method = "prod" )
11203
11212
11204
11213
@doc (make_doc ("mean" , ndim = 2 ))
11205
11214
def mean (
@@ -11209,7 +11218,10 @@ def mean(
11209
11218
numeric_only : bool = False ,
11210
11219
** kwargs ,
11211
11220
):
11212
- return super ().mean (axis , skipna , numeric_only , ** kwargs )
11221
+ result = super ().mean (axis , skipna , numeric_only , ** kwargs )
11222
+ if isinstance (result , Series ):
11223
+ result = result .__finalize__ (self , method = "mean" )
11224
+ return result
11213
11225
11214
11226
@doc (make_doc ("median" , ndim = 2 ))
11215
11227
def median (
@@ -11219,7 +11231,10 @@ def median(
11219
11231
numeric_only : bool = False ,
11220
11232
** kwargs ,
11221
11233
):
11222
- return super ().median (axis , skipna , numeric_only , ** kwargs )
11234
+ result = super ().median (axis , skipna , numeric_only , ** kwargs )
11235
+ if isinstance (result , Series ):
11236
+ result = result .__finalize__ (self , method = "median" )
11237
+ return result
11223
11238
11224
11239
@doc (make_doc ("sem" , ndim = 2 ))
11225
11240
def sem (
@@ -11230,7 +11245,10 @@ def sem(
11230
11245
numeric_only : bool = False ,
11231
11246
** kwargs ,
11232
11247
):
11233
- return super ().sem (axis , skipna , ddof , numeric_only , ** kwargs )
11248
+ result = super ().sem (axis , skipna , ddof , numeric_only , ** kwargs )
11249
+ if isinstance (result , Series ):
11250
+ result = result .__finalize__ (self , method = "sem" )
11251
+ return result
11234
11252
11235
11253
@doc (make_doc ("var" , ndim = 2 ))
11236
11254
def var (
@@ -11241,7 +11259,10 @@ def var(
11241
11259
numeric_only : bool = False ,
11242
11260
** kwargs ,
11243
11261
):
11244
- return super ().var (axis , skipna , ddof , numeric_only , ** kwargs )
11262
+ result = super ().var (axis , skipna , ddof , numeric_only , ** kwargs )
11263
+ if isinstance (result , Series ):
11264
+ result = result .__finalize__ (self , method = "var" )
11265
+ return result
11245
11266
11246
11267
@doc (make_doc ("std" , ndim = 2 ))
11247
11268
def std (
@@ -11252,8 +11273,10 @@ def std(
11252
11273
numeric_only : bool = False ,
11253
11274
** kwargs ,
11254
11275
):
11255
- result = cast (Series , super ().std (axis , skipna , ddof , numeric_only , ** kwargs ))
11256
- return result .__finalize__ (self , method = "std" )
11276
+ result = super ().std (axis , skipna , ddof , numeric_only , ** kwargs )
11277
+ if isinstance (result , Series ):
11278
+ result = result .__finalize__ (self , method = "std" )
11279
+ return result
11257
11280
11258
11281
@doc (make_doc ("skew" , ndim = 2 ))
11259
11282
def skew (
@@ -11263,7 +11286,10 @@ def skew(
11263
11286
numeric_only : bool = False ,
11264
11287
** kwargs ,
11265
11288
):
11266
- return super ().skew (axis , skipna , numeric_only , ** kwargs )
11289
+ result = super ().skew (axis , skipna , numeric_only , ** kwargs )
11290
+ if isinstance (result , Series ):
11291
+ result = result .__finalize__ (self , method = "skew" )
11292
+ return result
11267
11293
11268
11294
@doc (make_doc ("kurt" , ndim = 2 ))
11269
11295
def kurt (
@@ -11273,7 +11299,10 @@ def kurt(
11273
11299
numeric_only : bool = False ,
11274
11300
** kwargs ,
11275
11301
):
11276
- return super ().kurt (axis , skipna , numeric_only , ** kwargs )
11302
+ result = super ().kurt (axis , skipna , numeric_only , ** kwargs )
11303
+ if isinstance (result , Series ):
11304
+ result = result .__finalize__ (self , method = "kurt" )
11305
+ return result
11277
11306
11278
11307
kurtosis = kurt
11279
11308
product = prod
0 commit comments