Skip to content

Commit 9aa0159

Browse files
committed
Treating na values as none for clips
1 parent 34c4ffd commit 9aa0159

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Diff for: pandas/core/generic.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -4660,9 +4660,6 @@ def _clip_with_one_bound(self, threshold, method, axis, inplace):
46604660
if axis is not None:
46614661
axis = self._get_axis_number(axis)
46624662

4663-
if np.any(isna(threshold)):
4664-
raise ValueError("Cannot use an NA value as a clip threshold")
4665-
46664663
# method is self.le for upper bound and self.ge for lower bound
46674664
if is_scalar(threshold) and is_number(threshold):
46684665
if method.__name__ == 'le':
@@ -4742,6 +4739,12 @@ def clip(self, lower=None, upper=None, axis=None, inplace=False,
47424739

47434740
axis = nv.validate_clip_with_axis(axis, args, kwargs)
47444741

4742+
# GH 17276
4743+
if np.any(pd.isnull(lower)):
4744+
lower = None
4745+
if np.any(pd.isnull(upper)):
4746+
upper = None
4747+
47454748
# GH 2747 (arguments were reversed)
47464749
if lower is not None and upper is not None:
47474750
if is_scalar(lower) and is_scalar(upper):
@@ -4758,7 +4761,6 @@ def clip(self, lower=None, upper=None, axis=None, inplace=False,
47584761
if upper is not None:
47594762
if inplace:
47604763
result = self
4761-
47624764
result = result.clip_upper(upper, axis, inplace=inplace)
47634765

47644766
return result

0 commit comments

Comments
 (0)