@@ -2801,14 +2801,16 @@ def notnull(self):
2801
2801
"""
2802
2802
return notnull (self ).__finalize__ (self )
2803
2803
2804
- def clip (self , lower = None , upper = None , out = None ):
2804
+ def clip (self , lower = None , upper = None , out = None , axis = None ):
2805
2805
"""
2806
2806
Trim values at input threshold(s)
2807
2807
2808
2808
Parameters
2809
2809
----------
2810
2810
lower : float or array_like, default None
2811
2811
upper : float or array_like, default None
2812
+ axis : int, optional
2813
+ Align object with lower and upper along the given axis.
2812
2814
2813
2815
Returns
2814
2816
-------
@@ -2824,19 +2826,21 @@ def clip(self, lower=None, upper=None, out=None):
2824
2826
2825
2827
result = self
2826
2828
if lower is not None :
2827
- result = result .clip_lower (lower )
2829
+ result = result .clip_lower (lower , axis )
2828
2830
if upper is not None :
2829
- result = result .clip_upper (upper )
2831
+ result = result .clip_upper (upper , axis )
2830
2832
2831
2833
return result
2832
2834
2833
- def clip_upper (self , threshold ):
2835
+ def clip_upper (self , threshold , axis = None ):
2834
2836
"""
2835
2837
Return copy of input with values above given value(s) truncated
2836
2838
2837
2839
Parameters
2838
2840
----------
2839
2841
threshold : float or array_like
2842
+ axis : int, optional
2843
+ Align object with threshold along the given axis.
2840
2844
2841
2845
See also
2842
2846
--------
@@ -2849,15 +2853,22 @@ def clip_upper(self, threshold):
2849
2853
if np .any (isnull (threshold )):
2850
2854
raise ValueError ("Cannot use an NA value as a clip threshold" )
2851
2855
2852
- return self .where (self .le (threshold , axis = 0 ) | isnull (self ), threshold , axis = 0 )
2856
+ if axis is None :
2857
+ return self .where (self .le (threshold ) | isnull (self ), threshold )
2858
+ else :
2859
+ subset = self .le (threshold , axis = axis ) | isnull (self )
2860
+ return self .where (subset , threshold , axis = axis )
2861
+
2853
2862
2854
- def clip_lower (self , threshold ):
2863
+ def clip_lower (self , threshold , axis = None ):
2855
2864
"""
2856
2865
Return copy of the input with values below given value(s) truncated
2857
2866
2858
2867
Parameters
2859
2868
----------
2860
2869
threshold : float or array_like
2870
+ axis : int, optional
2871
+ Align object with threshold along the given axis.
2861
2872
2862
2873
See also
2863
2874
--------
@@ -2870,7 +2881,12 @@ def clip_lower(self, threshold):
2870
2881
if np .any (isnull (threshold )):
2871
2882
raise ValueError ("Cannot use an NA value as a clip threshold" )
2872
2883
2873
- return self .where (self .ge (threshold , axis = 0 ) | isnull (self ), threshold , axis = 0 )
2884
+ if axis is None :
2885
+ return self .where (self .ge (threshold ) | isnull (self ), threshold )
2886
+ else :
2887
+ subset = self .ge (threshold , axis = axis ) | isnull (self )
2888
+ return self .where (subset , threshold , axis = axis )
2889
+
2874
2890
2875
2891
def groupby (self , by = None , axis = 0 , level = None , as_index = True , sort = True ,
2876
2892
group_keys = True , squeeze = False ):
0 commit comments