Skip to content

Commit fe1ab74

Browse files
author
Andrew Archer
committed
BUG: Silence numpy warnings when broadcasting DataFrame to Series with comparison ops (GH16378, GH16306)
TST: test for fix of GH16378, GH16306
1 parent d5a681b commit fe1ab74

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

doc/source/whatsnew/v0.20.2.txt

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Conversion
4242
^^^^^^^^^^
4343

4444
- Bug in ``pd.to_numeric()`` in which empty data inputs were causing Python to crash (:issue:`16302`)
45+
- Silence numpy warnings when broadcasting DataFrame to Series with comparison ops (:issue:`16378`, :issue:`16306`)
4546

4647

4748
Indexing

pandas/core/ops.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,8 @@ def _flex_comp_method_FRAME(op, name, str_rep=None, default_axis='columns',
12501250
masker=False):
12511251
def na_op(x, y):
12521252
try:
1253-
result = op(x, y)
1253+
with np.errstate(invalid='ignore'):
1254+
result = op(x, y)
12541255
except TypeError:
12551256
xrav = x.ravel()
12561257
result = np.empty(x.size, dtype=bool)

pandas/tests/frame/test_analytics.py

+13
Original file line numberDiff line numberDiff line change
@@ -2073,3 +2073,16 @@ def test_n_duplicate_index(self, df_duplicates, n, order):
20732073
result = df.nlargest(n, order)
20742074
expected = df.sort_values(order, ascending=False).head(n)
20752075
tm.assert_frame_equal(result, expected)
2076+
2077+
def test_series_broadcasting(self):
2078+
# smoke test for numpy warnings
2079+
# GH 16378, GH 16306
2080+
df = DataFrame({'A': [np.nan, 2.0, np.nan]})
2081+
s = Series([1, 1, 1])
2082+
2083+
with tm.assert_produces_warning(None):
2084+
df.clip_lower(s, axis=0)
2085+
df.gt(s, axis=0)
2086+
df.lt(s, axis=0)
2087+
df.le(s, axis=0)
2088+
df.ge(s, axis=0)

pandas/tests/frame/test_convert_to.py

+1
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,4 @@ def test_to_records_datetimeindex_with_tz(self, tz):
229229

230230
# both converted to UTC, so they are equal
231231
tm.assert_numpy_array_equal(result, expected)
232+

0 commit comments

Comments
 (0)