Skip to content

Commit

Permalink
TST: followup to pandas-dev#16364, catch errstate warnings (pandas-de…
Browse files Browse the repository at this point in the history
  • Loading branch information
jreback authored and pcluo committed May 22, 2017
1 parent ea1945e commit 04ab907
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
14 changes: 9 additions & 5 deletions pandas/core/generic.py
Expand Up @@ -4113,11 +4113,15 @@ def _clip_with_scalar(self, lower, upper):

result = self.values
mask = isnull(result)
if upper is not None:
result = np.where(result >= upper, upper, result)
if lower is not None:
result = np.where(result <= lower, lower, result)
result[mask] = np.nan

with np.errstate(all='ignore'):
if upper is not None:
result = np.where(result >= upper, upper, result)
if lower is not None:
result = np.where(result <= lower, lower, result)
if np.any(mask):
result[mask] = np.nan

return self._constructor(
result, **self._construct_axes_dict()).__finalize__(self)

Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/frame/test_analytics.py
Expand Up @@ -1824,6 +1824,17 @@ def test_dataframe_clip(self):
assert (clipped_df.values[ub_mask] == ub).all()
assert (clipped_df.values[mask] == df.values[mask]).all()

@pytest.mark.xfail(reason=("clip on mixed integer or floats "
"with integer clippers coerces to float"))
def test_clip_mixed_numeric(self):

df = DataFrame({'A': [1, 2, 3],
'B': [1., np.nan, 3.]})
result = df.clip(1, 2)
expected = DataFrame({'A': [1, 2, 2],
'B': [1., np.nan, 2.]})
tm.assert_frame_equal(result, expected, check_like=True)

def test_clip_against_series(self):
# GH #6966

Expand Down

0 comments on commit 04ab907

Please sign in to comment.