Skip to content

Commit

Permalink
BUG: Silence numpy warnings when broadcasting comparison ops (GH16378…
Browse files Browse the repository at this point in the history
…, GH16306) (#16433)

TST: test for fix of GH16378, GH16306(cherry picked from commit 96f3e7c)
  • Loading branch information
AndrewArcher authored and TomAugspurger committed May 30, 2017
1 parent 8ae7fd5 commit 0ffce83
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.20.2.txt
Expand Up @@ -44,6 +44,7 @@ Conversion
^^^^^^^^^^

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


Indexing
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/ops.py
Expand Up @@ -1250,7 +1250,8 @@ def _flex_comp_method_FRAME(op, name, str_rep=None, default_axis='columns',
masker=False):
def na_op(x, y):
try:
result = op(x, y)
with np.errstate(invalid='ignore'):
result = op(x, y)
except TypeError:
xrav = x.ravel()
result = np.empty(x.size, dtype=bool)
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/frame/test_analytics.py
Expand Up @@ -2056,3 +2056,16 @@ def test_n_duplicate_index(self, df_duplicates, n, order):
result = df.nlargest(n, order)
expected = df.sort_values(order, ascending=False).head(n)
tm.assert_frame_equal(result, expected)

def test_series_broadcasting(self):
# smoke test for numpy warnings
# GH 16378, GH 16306
df = DataFrame([1.0, 1.0, 1.0])
df_nan = DataFrame({'A': [np.nan, 2.0, np.nan]})
s = Series([1, 1, 1])
s_nan = Series([np.nan, np.nan, 1])

with tm.assert_produces_warning(None):
df_nan.clip_lower(s, axis=0)
for op in ['lt', 'le', 'gt', 'ge', 'eq', 'ne']:
getattr(df, op)(s_nan, axis=0)

0 comments on commit 0ffce83

Please sign in to comment.