@@ -2281,6 +2281,8 @@ def select(self, crit, axis=0):
2281
2281
"""
2282
2282
Return data corresponding to axis labels matching criteria
2283
2283
2284
+ DEPRECATED: use .loc(axis=)[crit] to select via labels
2285
+
2284
2286
Parameters
2285
2287
----------
2286
2288
crit : function
@@ -2291,6 +2293,11 @@ def select(self, crit, axis=0):
2291
2293
-------
2292
2294
selection : type of caller
2293
2295
"""
2296
+ warnings .warn ("select is deprecated and will be removed in a "
2297
+ "future release. You can use "
2298
+ ".loc[crit] as a replacement" ,
2299
+ FutureWarning , stacklevel = 2 )
2300
+
2294
2301
axis = self ._get_axis_number (axis )
2295
2302
axis_name = self ._get_axis_name (axis )
2296
2303
axis_values = self ._get_axis (axis )
@@ -3043,7 +3050,7 @@ def filter(self, items=None, like=None, regex=None, axis=None):
3043
3050
3044
3051
See Also
3045
3052
--------
3046
- pandas.DataFrame.select
3053
+ pandas.DataFrame.loc
3047
3054
3048
3055
Notes
3049
3056
-----
@@ -3062,20 +3069,23 @@ def filter(self, items=None, like=None, regex=None, axis=None):
3062
3069
3063
3070
if axis is None :
3064
3071
axis = self ._info_axis_name
3065
- axis_name = self ._get_axis_name (axis )
3066
- axis_values = self ._get_axis (axis_name )
3072
+ labels = self ._get_axis (axis )
3067
3073
3068
3074
if items is not None :
3069
- return self .reindex (** {axis_name :
3070
- [r for r in items if r in axis_values ]})
3075
+ name = self ._get_axis_name (axis )
3076
+ return self .reindex (
3077
+ ** {name : [r for r in items if r in labels ]})
3071
3078
elif like :
3072
- matchf = lambda x : (like in x if isinstance (x , string_types ) else
3073
- like in str (x ))
3074
- return self .select (matchf , axis = axis_name )
3079
+ def f (x ):
3080
+ if not isinstance (x , string_types ):
3081
+ x = str (x )
3082
+ return like in x
3083
+ values = labels .map (f )
3084
+ return self .loc (axis = axis )[values .values ]
3075
3085
elif regex :
3076
3086
matcher = re .compile (regex )
3077
- return self . select (lambda x : matcher .search (str (x )) is not None ,
3078
- axis = axis_name )
3087
+ values = labels . map (lambda x : matcher .search (str (x )) is not None )
3088
+ return self . loc ( axis = axis )[ values . values ]
3079
3089
else :
3080
3090
raise TypeError ('Must pass either `items`, `like`, or `regex`' )
3081
3091
@@ -5698,7 +5708,7 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
5698
5708
inplace = validate_bool_kwarg (inplace , 'inplace' )
5699
5709
5700
5710
# align the cond to same shape as myself
5701
- cond = com ._apply_if_callable (cond , self )
5711
+ cond = com ._apply_if_callable (cond , self , axis = axis )
5702
5712
if isinstance (cond , NDFrame ):
5703
5713
cond , _ = cond .align (self , join = 'right' , broadcast_axis = 1 )
5704
5714
else :
@@ -5939,7 +5949,7 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
5939
5949
def where (self , cond , other = np .nan , inplace = False , axis = None , level = None ,
5940
5950
try_cast = False , raise_on_error = True ):
5941
5951
5942
- other = com ._apply_if_callable (other , self )
5952
+ other = com ._apply_if_callable (other , self , axis = axis )
5943
5953
return self ._where (cond , other , inplace , axis , level , try_cast ,
5944
5954
raise_on_error )
5945
5955
@@ -5950,7 +5960,7 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None,
5950
5960
try_cast = False , raise_on_error = True ):
5951
5961
5952
5962
inplace = validate_bool_kwarg (inplace , 'inplace' )
5953
- cond = com ._apply_if_callable (cond , self )
5963
+ cond = com ._apply_if_callable (cond , self , axis = axis )
5954
5964
5955
5965
return self .where (~ cond , other = other , inplace = inplace , axis = axis ,
5956
5966
level = level , try_cast = try_cast ,
0 commit comments