Skip to content

Commit

Permalink
adding clip tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mgasvoda committed Aug 18, 2017
1 parent 9aa0159 commit d9627fe
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
40 changes: 24 additions & 16 deletions pandas/tests/frame/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1931,22 +1931,30 @@ def test_clip_against_frame(self, axis):
tm.assert_frame_equal(clipped_df[ub_mask], ub[ub_mask])
tm.assert_frame_equal(clipped_df[mask], df[mask])

def test_clip_na(self):
msg = "Cannot use an NA"
with tm.assert_raises_regex(ValueError, msg):
self.frame.clip(lower=np.nan)

with tm.assert_raises_regex(ValueError, msg):
self.frame.clip(lower=[np.nan])

with tm.assert_raises_regex(ValueError, msg):
self.frame.clip(upper=np.nan)

with tm.assert_raises_regex(ValueError, msg):
self.frame.clip(upper=[np.nan])

with tm.assert_raises_regex(ValueError, msg):
self.frame.clip(lower=np.nan, upper=np.nan)
# def test_clip_na(self):
# msg = "Cannot use an NA"
# with tm.assert_raises_regex(ValueError, msg):
# self.frame.clip(lower=np.nan)

# with tm.assert_raises_regex(ValueError, msg):
# self.frame.clip(lower=[np.nan])

# with tm.assert_raises_regex(ValueError, msg):
# self.frame.clip(upper=np.nan)

# with tm.assert_raises_regex(ValueError, msg):
# self.frame.clip(upper=[np.nan])

# with tm.assert_raises_regex(ValueError, msg):
# self.frame.clip(lower=np.nan, upper=np.nan)

def test_clip_with_na_args(self):
"""Should process np.nan argument as None """
# GH # 17276
self.frame.clip(np.nan)
self.frame.clip(upper=[1,2,np.nan])
self.frame.clip(lower=[1,np.nan,3])
self.frame.clip(upper=np.nan, lower=np.nan)

# Matrix-like

Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/series/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,15 @@ def test_clip_types_and_nulls(self):
assert list(isna(s)) == list(isna(l))
assert list(isna(s)) == list(isna(u))

def test_clip_with_na_args(self):
"""Should process np.nan argument as None """
# GH # 17276
s = Series([1,2,3])
s.clip(np.nan)
s.clip(upper=[1,2,np.nan])
s.clip(lower=[1,np.nan,3])
s.clip(upper=np.nan, lower=np.nan)

def test_clip_against_series(self):
# GH #6966

Expand Down

0 comments on commit d9627fe

Please sign in to comment.