@@ -2339,6 +2339,8 @@ def select(self, crit, axis=0):
23392339 """
23402340 Return data corresponding to axis labels matching criteria
23412341
2342+ DEPRECATED: use .loc(axis=)[crit] to select via labels
2343+
23422344 Parameters
23432345 ----------
23442346 crit : function
@@ -2349,6 +2351,11 @@ def select(self, crit, axis=0):
23492351 -------
23502352 selection : type of caller
23512353 """
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+
23522359 axis = self ._get_axis_number (axis )
23532360 axis_name = self ._get_axis_name (axis )
23542361 axis_values = self ._get_axis (axis )
@@ -3101,7 +3108,7 @@ def filter(self, items=None, like=None, regex=None, axis=None):
31013108
31023109 See Also
31033110 --------
3104- pandas.DataFrame.select
3111+ pandas.DataFrame.loc
31053112
31063113 Notes
31073114 -----
@@ -3120,20 +3127,23 @@ def filter(self, items=None, like=None, regex=None, axis=None):
31203127
31213128 if axis is None :
31223129 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 )
31253131
31263132 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 ]})
31293136 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 ]
31333143 elif regex :
31343144 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 ]
31373147 else :
31383148 raise TypeError ('Must pass either `items`, `like`, or `regex`' )
31393149
@@ -5756,7 +5766,7 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
57565766 inplace = validate_bool_kwarg (inplace , 'inplace' )
57575767
57585768 # 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 )
57605770 if isinstance (cond , NDFrame ):
57615771 cond , _ = cond .align (self , join = 'right' , broadcast_axis = 1 )
57625772 else :
@@ -5997,7 +6007,7 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
59976007 def where (self , cond , other = np .nan , inplace = False , axis = None , level = None ,
59986008 try_cast = False , raise_on_error = True ):
59996009
6000- other = com ._apply_if_callable (other , self )
6010+ other = com ._apply_if_callable (other , self , axis = axis )
60016011 return self ._where (cond , other , inplace , axis , level , try_cast ,
60026012 raise_on_error )
60036013
@@ -6008,7 +6018,7 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None,
60086018 try_cast = False , raise_on_error = True ):
60096019
60106020 inplace = validate_bool_kwarg (inplace , 'inplace' )
6011- cond = com ._apply_if_callable (cond , self )
6021+ cond = com ._apply_if_callable (cond , self , axis = axis )
60126022
60136023 return self .where (~ cond , other = other , inplace = inplace , axis = axis ,
60146024 level = level , try_cast = try_cast ,
0 commit comments