From d9627fe4c715402996ecc3d657680715d6f2c2b1 Mon Sep 17 00:00:00 2001 From: Michael Gasvoda Date: Fri, 18 Aug 2017 16:28:46 -0400 Subject: [PATCH] adding clip tests --- pandas/tests/frame/test_analytics.py | 40 ++++++++++++++++----------- pandas/tests/series/test_analytics.py | 9 ++++++ 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index 484a09f11b58a..79e6aec2185ea 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -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 diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index 44da0968d7024..7a9ffb2a62411 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -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