@@ -2281,6 +2281,8 @@ def select(self, crit, axis=0):
22812281 """
22822282 Return data corresponding to axis labels matching criteria
22832283
2284+ DEPRECATED: use .loc(axis=)[crit] to select via labels
2285+
22842286 Parameters
22852287 ----------
22862288 crit : function
@@ -2291,6 +2293,11 @@ def select(self, crit, axis=0):
22912293 -------
22922294 selection : type of caller
22932295 """
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+
22942301 axis = self ._get_axis_number (axis )
22952302 axis_name = self ._get_axis_name (axis )
22962303 axis_values = self ._get_axis (axis )
@@ -3043,7 +3050,7 @@ def filter(self, items=None, like=None, regex=None, axis=None):
30433050
30443051 See Also
30453052 --------
3046- pandas.DataFrame.select
3053+ pandas.DataFrame.loc
30473054
30483055 Notes
30493056 -----
@@ -3062,20 +3069,23 @@ def filter(self, items=None, like=None, regex=None, axis=None):
30623069
30633070 if axis is None :
30643071 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 )
30673073
30683074 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 ]})
30713078 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 ]
30753085 elif regex :
30763086 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 ]
30793089 else :
30803090 raise TypeError ('Must pass either `items`, `like`, or `regex`' )
30813091
@@ -5698,7 +5708,7 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
56985708 inplace = validate_bool_kwarg (inplace , 'inplace' )
56995709
57005710 # 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 )
57025712 if isinstance (cond , NDFrame ):
57035713 cond , _ = cond .align (self , join = 'right' , broadcast_axis = 1 )
57045714 else :
@@ -5939,7 +5949,7 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
59395949 def where (self , cond , other = np .nan , inplace = False , axis = None , level = None ,
59405950 try_cast = False , raise_on_error = True ):
59415951
5942- other = com ._apply_if_callable (other , self )
5952+ other = com ._apply_if_callable (other , self , axis = axis )
59435953 return self ._where (cond , other , inplace , axis , level , try_cast ,
59445954 raise_on_error )
59455955
@@ -5950,7 +5960,7 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None,
59505960 try_cast = False , raise_on_error = True ):
59515961
59525962 inplace = validate_bool_kwarg (inplace , 'inplace' )
5953- cond = com ._apply_if_callable (cond , self )
5963+ cond = com ._apply_if_callable (cond , self , axis = axis )
59545964
59555965 return self .where (~ cond , other = other , inplace = inplace , axis = axis ,
59565966 level = level , try_cast = try_cast ,
0 commit comments