Skip to content

Commit e0e0d04

Browse files
yl2526jreback
authored andcommitted
change inplace check position
1 parent ef2dc76 commit e0e0d04

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

pandas/core/generic.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4415,26 +4415,25 @@ def _clip_with_scalar(self, lower, upper, inplace=False):
44154415

44164416
def _clip_with_one_bound(self, threshold, method, axis, inplace):
44174417

4418+
inplace = validate_bool_kwarg(inplace, 'inplace')
4419+
44184420
if np.any(isnull(threshold)):
44194421
raise ValueError("Cannot use an NA value as a clip threshold")
44204422

44214423
# method is self.le for upper bound and self.ge for lower bound
44224424
if is_scalar(threshold) and is_number(threshold):
44234425
if method.__name__ == 'le':
44244426
return self._clip_with_scalar(None, threshold, inplace=inplace)
4425-
else:
4426-
return self._clip_with_scalar(threshold, None, inplace=inplace)
4427-
4428-
inplace = validate_bool_kwarg(inplace, 'inplace')
4427+
return self._clip_with_scalar(threshold, None, inplace=inplace)
44294428

44304429
subset = method(threshold, axis=axis) | isnull(self)
44314430

44324431
# GH #15390
4433-
if is_scalar(threshold) or is_number(threshold):
4432+
if is_scalar(threshold):
44344433
return self.where(subset, threshold, axis=axis, inplace=inplace)
44354434

44364435
# For arry_like threshold, convet it to Series with corret index
4437-
# `where` only takes
4436+
# `where` takes scalar, NDFrame, or callable for argument "other"
44384437
try:
44394438
if isinstance(subset, ABCSeries):
44404439
threshold = pd.Series(threshold, index=subset.index)

pandas/tests/series/test_analytics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ def test_clip_against_list(self, inplace):
10211021
original = pd.Series([5, 6, 7])
10221022
result = original.clip(upper=[1, 2, 3], inplace=inplace)
10231023
expected = pd.Series([1, 2, 3])
1024-
1024+
10251025
if inplace:
10261026
tm.assert_series_equal(original, expected, check_exact=True)
10271027
else:

0 commit comments

Comments
 (0)