@@ -2279,6 +2279,8 @@ def select(self, crit, axis=0):
2279
2279
"""
2280
2280
Return data corresponding to axis labels matching criteria
2281
2281
2282
+ DEPRECATED: use .loc(axis=)[crit] to select via labels
2283
+
2282
2284
Parameters
2283
2285
----------
2284
2286
crit : function
@@ -2289,6 +2291,11 @@ def select(self, crit, axis=0):
2289
2291
-------
2290
2292
selection : type of caller
2291
2293
"""
2294
+ warnings .warn ("select is deprecated and will be removed in a "
2295
+ "future release. You can use "
2296
+ ".loc(axis=)[crit] as a replacement" ,
2297
+ FutureWarning , stacklevel = 2 )
2298
+
2292
2299
axis = self ._get_axis_number (axis )
2293
2300
axis_name = self ._get_axis_name (axis )
2294
2301
axis_values = self ._get_axis (axis )
@@ -2991,7 +2998,7 @@ def filter(self, items=None, like=None, regex=None, axis=None):
2991
2998
2992
2999
See Also
2993
3000
--------
2994
- pandas.DataFrame.select
3001
+ pandas.DataFrame.loc
2995
3002
2996
3003
Notes
2997
3004
-----
@@ -3010,20 +3017,23 @@ def filter(self, items=None, like=None, regex=None, axis=None):
3010
3017
3011
3018
if axis is None :
3012
3019
axis = self ._info_axis_name
3013
- axis_name = self ._get_axis_name (axis )
3014
- axis_values = self ._get_axis (axis_name )
3020
+ labels = self ._get_axis (axis )
3015
3021
3016
3022
if items is not None :
3017
- return self .reindex (** {axis_name :
3018
- [r for r in items if r in axis_values ]})
3023
+ name = self ._get_axis_name (axis )
3024
+ return self .reindex (
3025
+ ** {name : [r for r in items if r in labels ]})
3019
3026
elif like :
3020
- matchf = lambda x : (like in x if isinstance (x , string_types ) else
3021
- like in str (x ))
3022
- return self .select (matchf , axis = axis_name )
3027
+ def f (x ):
3028
+ if not isinstance (x , string_types ):
3029
+ x = str (x )
3030
+ return like in x
3031
+ values = labels .map (f )
3032
+ return self .loc (axis = axis )[values .values ]
3023
3033
elif regex :
3024
3034
matcher = re .compile (regex )
3025
- return self . select (lambda x : matcher .search (str (x )) is not None ,
3026
- axis = axis_name )
3035
+ values = labels . map (lambda x : matcher .search (str (x )) is not None )
3036
+ return self . loc ( axis = axis )[ values . values ]
3027
3037
else :
3028
3038
raise TypeError ('Must pass either `items`, `like`, or `regex`' )
3029
3039
@@ -5643,7 +5653,7 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
5643
5653
inplace = validate_bool_kwarg (inplace , 'inplace' )
5644
5654
5645
5655
# align the cond to same shape as myself
5646
- cond = com ._apply_if_callable (cond , self )
5656
+ cond = com ._apply_if_callable (cond , self , axis = axis )
5647
5657
if isinstance (cond , NDFrame ):
5648
5658
cond , _ = cond .align (self , join = 'right' , broadcast_axis = 1 )
5649
5659
else :
@@ -5865,7 +5875,7 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
5865
5875
def where (self , cond , other = np .nan , inplace = False , axis = None , level = None ,
5866
5876
try_cast = False , raise_on_error = True ):
5867
5877
5868
- other = com ._apply_if_callable (other , self )
5878
+ other = com ._apply_if_callable (other , self , axis = axis )
5869
5879
return self ._where (cond , other , inplace , axis , level , try_cast ,
5870
5880
raise_on_error )
5871
5881
@@ -5875,7 +5885,7 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None,
5875
5885
try_cast = False , raise_on_error = True ):
5876
5886
5877
5887
inplace = validate_bool_kwarg (inplace , 'inplace' )
5878
- cond = com ._apply_if_callable (cond , self )
5888
+ cond = com ._apply_if_callable (cond , self , axis = axis )
5879
5889
5880
5890
return self .where (~ cond , other = other , inplace = inplace , axis = axis ,
5881
5891
level = level , try_cast = try_cast ,
0 commit comments