@@ -2339,6 +2339,8 @@ def select(self, crit, axis=0):
2339
2339
"""
2340
2340
Return data corresponding to axis labels matching criteria
2341
2341
2342
+ DEPRECATED: use .loc(axis=)[crit] to select via labels
2343
+
2342
2344
Parameters
2343
2345
----------
2344
2346
crit : function
@@ -2349,6 +2351,11 @@ def select(self, crit, axis=0):
2349
2351
-------
2350
2352
selection : type of caller
2351
2353
"""
2354
+ warnings .warn ("select is deprecated and will be removed in a "
2355
+ "future release. You can use "
2356
+ ".loc[crit] as a replacement" ,
2357
+ FutureWarning , stacklevel = 2 )
2358
+
2352
2359
axis = self ._get_axis_number (axis )
2353
2360
axis_name = self ._get_axis_name (axis )
2354
2361
axis_values = self ._get_axis (axis )
@@ -3101,7 +3108,7 @@ def filter(self, items=None, like=None, regex=None, axis=None):
3101
3108
3102
3109
See Also
3103
3110
--------
3104
- pandas.DataFrame.select
3111
+ pandas.DataFrame.loc
3105
3112
3106
3113
Notes
3107
3114
-----
@@ -3120,20 +3127,23 @@ def filter(self, items=None, like=None, regex=None, axis=None):
3120
3127
3121
3128
if axis is None :
3122
3129
axis = self ._info_axis_name
3123
- axis_name = self ._get_axis_name (axis )
3124
- axis_values = self ._get_axis (axis_name )
3130
+ labels = self ._get_axis (axis )
3125
3131
3126
3132
if items is not None :
3127
- return self .reindex (** {axis_name :
3128
- [r for r in items if r in axis_values ]})
3133
+ name = self ._get_axis_name (axis )
3134
+ return self .reindex (
3135
+ ** {name : [r for r in items if r in labels ]})
3129
3136
elif like :
3130
- matchf = lambda x : (like in x if isinstance (x , string_types ) else
3131
- like in str (x ))
3132
- return self .select (matchf , axis = axis_name )
3137
+ def f (x ):
3138
+ if not isinstance (x , string_types ):
3139
+ x = str (x )
3140
+ return like in x
3141
+ values = labels .map (f )
3142
+ return self .loc (axis = axis )[values .values ]
3133
3143
elif regex :
3134
3144
matcher = re .compile (regex )
3135
- return self . select (lambda x : matcher .search (str (x )) is not None ,
3136
- axis = axis_name )
3145
+ values = labels . map (lambda x : matcher .search (str (x )) is not None )
3146
+ return self . loc ( axis = axis )[ values . values ]
3137
3147
else :
3138
3148
raise TypeError ('Must pass either `items`, `like`, or `regex`' )
3139
3149
@@ -5756,7 +5766,7 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
5756
5766
inplace = validate_bool_kwarg (inplace , 'inplace' )
5757
5767
5758
5768
# align the cond to same shape as myself
5759
- cond = com ._apply_if_callable (cond , self )
5769
+ cond = com ._apply_if_callable (cond , self , axis = axis )
5760
5770
if isinstance (cond , NDFrame ):
5761
5771
cond , _ = cond .align (self , join = 'right' , broadcast_axis = 1 )
5762
5772
else :
@@ -5997,7 +6007,7 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
5997
6007
def where (self , cond , other = np .nan , inplace = False , axis = None , level = None ,
5998
6008
try_cast = False , raise_on_error = True ):
5999
6009
6000
- other = com ._apply_if_callable (other , self )
6010
+ other = com ._apply_if_callable (other , self , axis = axis )
6001
6011
return self ._where (cond , other , inplace , axis , level , try_cast ,
6002
6012
raise_on_error )
6003
6013
@@ -6008,7 +6018,7 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None,
6008
6018
try_cast = False , raise_on_error = True ):
6009
6019
6010
6020
inplace = validate_bool_kwarg (inplace , 'inplace' )
6011
- cond = com ._apply_if_callable (cond , self )
6021
+ cond = com ._apply_if_callable (cond , self , axis = axis )
6012
6022
6013
6023
return self .where (~ cond , other = other , inplace = inplace , axis = axis ,
6014
6024
level = level , try_cast = try_cast ,
0 commit comments