@@ -1080,34 +1080,13 @@ def nsmallest(
1080
1080
1081
1081
@doc (Series .idxmin .__doc__ )
1082
1082
def idxmin (self , axis : Axis = 0 , skipna : bool = True ) -> Series | DataFrame :
1083
- def func (df ):
1084
- return df .idxmin (axis = axis , skipna = skipna )
1085
-
1086
- func .__name__ = "idxmin"
1087
- return self ._idxmin_idxmax (func )
1083
+ result = self ._op_via_apply ("idxmax" , axis = axis , skipna = skipna )
1084
+ return result .astype (self ._obj_with_exclusions .index .dtype )
1088
1085
1089
1086
@doc (Series .idxmax .__doc__ )
1090
1087
def idxmax (self , axis : Axis = 0 , skipna : bool = True ) -> Series | DataFrame :
1091
- def func (df ):
1092
- return df .idxmax (axis = axis , skipna = skipna )
1093
-
1094
- func .__name__ = "idxmax"
1095
- return self ._idxmin_idxmax (func )
1096
-
1097
- def _idxmin_idxmax (self , func : Callable ) -> DataFrame | Series :
1098
- result , _ = self .grouper .apply (func , self ._obj_with_exclusions , self .axis )
1099
-
1100
- if len (result ) == 0 :
1101
- return self .obj ._constructor (
1102
- index = self .grouper .result_index ,
1103
- name = self ._obj_with_exclusions .name ,
1104
- dtype = self ._obj_with_exclusions .index .dtype ,
1105
- )
1106
-
1107
- else :
1108
- return self ._wrap_applied_output (
1109
- self ._obj_with_exclusions , result , not_indexed_same = True
1110
- )
1088
+ result = self ._op_via_apply ("idxmin" , axis = axis , skipna = skipna )
1089
+ return result .astype (self ._obj_with_exclusions .index .dtype )
1111
1090
1112
1091
@doc (Series .corr .__doc__ )
1113
1092
def corr (
@@ -2037,8 +2016,10 @@ def idxmax(
2037
2016
def func (df ):
2038
2017
return df .idxmax (axis = axis , skipna = skipna , numeric_only = numeric_only )
2039
2018
2040
- func .__name__ = "idxmax"
2041
- return self ._idxmin_idxmax (func )
2019
+ result = self ._python_apply_general (
2020
+ func , self ._obj_with_exclusions , not_indexed_same = True
2021
+ )
2022
+ return result .astype (self ._obj_with_exclusions .index .dtype , copy = False )
2042
2023
2043
2024
def idxmin (
2044
2025
self ,
@@ -2120,25 +2101,13 @@ def idxmin(
2120
2101
def func (df ):
2121
2102
return df .idxmin (axis = axis , skipna = skipna , numeric_only = numeric_only )
2122
2103
2123
- func .__name__ = "idxmin"
2124
- return self ._idxmin_idxmax (func )
2104
+ result = self ._python_apply_general (
2105
+ func , self ._obj_with_exclusions , not_indexed_same = True
2106
+ )
2107
+ return result .astype (self ._obj_with_exclusions .index .dtype , copy = False )
2125
2108
2126
2109
boxplot = boxplot_frame_groupby
2127
2110
2128
- def _idxmin_idxmax (self , func : Callable ) -> DataFrame :
2129
- result , _ = self .grouper .apply (func , self ._obj_with_exclusions , self .axis )
2130
-
2131
- if len (result ) == 0 :
2132
- return self .obj ._constructor (
2133
- index = self .grouper .result_index ,
2134
- columns = self ._obj_with_exclusions .columns ,
2135
- dtype = self ._obj_with_exclusions .index .dtype ,
2136
- )
2137
- else :
2138
- return self ._wrap_applied_output (
2139
- self ._obj_with_exclusions , result , not_indexed_same = True
2140
- )
2141
-
2142
2111
def value_counts (
2143
2112
self ,
2144
2113
subset : Sequence [Hashable ] | None = None ,
0 commit comments