Skip to content

TST: followup to #16364, catch errstate warnings #16373

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

Merged
merged 1 commit into from
May 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 9 additions & 5 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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