10000 BUG: clip should handle null values by mgasvoda · Pull Request #17288 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

BUG: clip should handle null values #17288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
adding clip tests
  • Loading branch information
mgasvoda committed Aug 18, 2017
commit d9627fe4c715402996ecc3d657680715d6f2c2b1
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to check the result of these function calls as part of the test.


# 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above


def test_clip_against_series(self):
# GH #6966

Expand Down
0