Skip to content

Commit 04ab907

Browse files
jrebackpcluo
authored andcommitted
TST: followup to pandas-dev#16364, catch errstate warnings (pandas-dev#16373)
1 parent ea1945e commit 04ab907

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

pandas/core/generic.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -4113,11 +4113,15 @@ def _clip_with_scalar(self, lower, upper):
41134113

41144114
result = self.values
41154115
mask = isnull(result)
4116-
if upper is not None:
4117-
result = np.where(result >= upper, upper, result)
4118-
if lower is not None:
4119-
result = np.where(result <= lower, lower, result)
4120-
result[mask] = np.nan
4116+
4117+
with np.errstate(all='ignore'):
4118+
if upper is not None:
4119+
result = np.where(result >= upper, upper, result)
4120+
if lower is not None:
4121+
result = np.where(result <= lower, lower, result)
4122+
if np.any(mask):
4123+
result[mask] = np.nan
4124+
41214125
return self._constructor(
41224126
result, **self._construct_axes_dict()).__finalize__(self)
41234127

pandas/tests/frame/test_analytics.py

+11
Original file line numberDiff line numberDiff line change
@@ -1824,6 +1824,17 @@ def test_dataframe_clip(self):
18241824
assert (clipped_df.values[ub_mask] == ub).all()
18251825
assert (clipped_df.values[mask] == df.values[mask]).all()
18261826

1827+
@pytest.mark.xfail(reason=("clip on mixed integer or floats "
1828+
"with integer clippers coerces to float"))
1829+
def test_clip_mixed_numeric(self):
1830+
1831+
df = DataFrame({'A': [1, 2, 3],
1832+
'B': [1., np.nan, 3.]})
1833+
result = df.clip(1, 2)
1834+
expected = DataFrame({'A': [1, 2, 2],
1835+
'B': [1., np.nan, 2.]})
1836+
tm.assert_frame_equal(result, expected, check_like=True)
1837+
18271838
def test_clip_against_series(self):
18281839
# GH #6966
18291840

0 commit comments

Comments
 (0)