@@ -4119,8 +4119,7 @@ def isnull(self):
4119
4119
def notnull (self ):
4120
4120
return notnull (self ).__finalize__ (self )
4121
4121
4122
- def _clip_with_scalar (self , lower , upper ):
4123
-
4122
+ def _clip_with_scalar (self , lower , upper , inplace = False ):
4124
4123
if ((lower is not None and np .any (isnull (lower ))) or
4125
4124
(upper is not None and np .any (isnull (upper )))):
4126
4125
raise ValueError ("Cannot use an NA value as a clip threshold" )
@@ -4136,10 +4135,15 @@ def _clip_with_scalar(self, lower, upper):
4136
4135
if np .any (mask ):
4137
4136
result [mask ] = np .nan
4138
4137
4139
- return self ._constructor (
4140
- result , ** self ._construct_axes_dict ()).__finalize__ (self )
4138
+ axes_dict = self ._construct_axes_dict ()
4139
+ result = self ._constructor (result , ** axes_dict ).__finalize__ (self )
4140
+
4141
+ if inplace :
4142
+ self ._update_inplace (result )
4143
+ else :
4144
+ return result
4141
4145
4142
- def clip (self , lower = None , upper = None , axis = None , * args , ** kwargs ):
4146
+ def clip (self , lower = None , upper = None , axis = None , inplace = False , * args , ** kwargs ):
4143
4147
"""
4144
4148
Trim values at input threshold(s).
4145
4149
@@ -4201,17 +4205,17 @@ def clip(self, lower=None, upper=None, axis=None, *args, **kwargs):
4201
4205
# fast-path for scalars
4202
4206
if ((lower is None or (is_scalar (lower ) and is_number (lower ))) and
4203
4207
(upper is None or (is_scalar (upper ) and is_number (upper )))):
4204
- return self ._clip_with_scalar (lower , upper )
4208
+ return self ._clip_with_scalar (lower , upper , inplace = inplace )
4205
4209
4206
4210
result = self
4207
4211
if lower is not None :
4208
- result = result .clip_lower (lower , axis )
4212
+ result = result .clip_lower (lower , axis , inplace = inplace )
4209
4213
if upper is not None :
4210
- result = result .clip_upper (upper , axis )
4214
+ result = result .clip_upper (upper , axis , inplace = inplace )
4211
4215
4212
4216
return result
4213
4217
4214
- def clip_upper (self , threshold , axis = None ):
4218
+ def clip_upper (self , threshold , axis = None , inplace = False ):
4215
4219
"""
4216
4220
Return copy of input with values above given value(s) truncated.
4217
4221
@@ -4233,12 +4237,12 @@ def clip_upper(self, threshold, axis=None):
4233
4237
raise ValueError ("Cannot use an NA value as a clip threshold" )
4234
4238
4235
4239
if is_scalar (threshold ) and is_number (threshold ):
4236
- return self ._clip_with_scalar (None , threshold )
4240
+ return self ._clip_with_scalar (None , threshold , inplace = inplace )
4237
4241
4238
4242
subset = self .le (threshold , axis = axis ) | isnull (self )
4239
- return self .where (subset , threshold , axis = axis )
4243
+ return self .where (subset , threshold , axis = axis , inplace = inplace )
4240
4244
4241
- def clip_lower (self , threshold , axis = None ):
4245
+ def clip_lower (self , threshold , axis = None , inplace = False ):
4242
4246
"""
4243
4247
Return copy of the input with values below given value(s) truncated.
4244
4248
@@ -4260,10 +4264,10 @@ def clip_lower(self, threshold, axis=None):
4260
4264
raise ValueError ("Cannot use an NA value as a clip threshold" )
4261
4265
4262
4266
if is_scalar (threshold ) and is_number (threshold ):
4263
- return self ._clip_with_scalar (threshold , None )
4267
+ return self ._clip_with_scalar (threshold , None , inplace = inplace )
4264
4268
4265
4269
subset = self .ge (threshold , axis = axis ) | isnull (self )
4266
- return self .where (subset , threshold , axis = axis )
4270
+ return self .where (subset , threshold , axis = axis , inplace = inplace )
4267
4271
4268
4272
def groupby (self , by = None , axis = 0 , level = None , as_index = True , sort = True ,
4269
4273
group_keys = True , squeeze = False , ** kwargs ):
0 commit comments