Skip to content

Commit

Permalink
Treating na values as none for clips
Browse files Browse the repository at this point in the history
  • Loading branch information
mgasvoda committed Aug 18, 2017
1 parent 34c4ffd commit 9aa0159
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4660,9 +4660,6 @@ def _clip_with_one_bound(self, threshold, method, axis, inplace):
if axis is not None:
axis = self._get_axis_number(axis)

if np.any(isna(threshold)):
raise ValueError("Cannot use an NA value as a clip threshold")

# method is self.le for upper bound and self.ge for lower bound
if is_scalar(threshold) and is_number(threshold):
if method.__name__ == 'le':
Expand Down Expand Up @@ -4742,6 +4739,12 @@ def clip(self, lower=None, upper=None, axis=None, inplace=False,

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

# GH 17276
if np.any(pd.isnull(lower)):
lower = None
if np.any(pd.isnull(upper)):
upper = None

# GH 2747 (arguments were reversed)
if lower is not None and upper is not None:
if is_scalar(lower) and is_scalar(upper):
Expand All @@ -4758,7 +4761,6 @@ def clip(self, lower=None, upper=None, axis=None, inplace=False,
if upper is not None:
if inplace:
result = self

result = result.clip_upper(upper, axis, inplace=inplace)

return result
Expand Down

0 comments on commit 9aa0159

Please sign in to comment.