Repository: spyder-ide/spyder

Issue:
RuntimeWarning when displaying min/max in the Variable Explorer
## Problem Description

Originally reported as numpy/numpy#11029

In numpy 1.14, umath.minimum.reduce and umath.maximum.reduce will raise `RuntimeWarning` if they encounter a NAN value. It seems the variable explorer is not filtering these warnings, so they turn up on the console when 
- max,min display is enabled in the variable explorer
- there is a NAN value in the ndarray

### What steps will reproduce the problem?
1. Use numpy 1.14.0 or later
2. Turn on max/min display by clicking to the variable explorer tab, clicking on the setup gear in the corner, and making sure "Show arrays min/max" checkbox is checked.
3. in the console, `import numpy as np; A=np.full(16, np.nan)'

Note that numpy 1.14.0 - 1.14.3 have a bug, doing `A=np.full(7, np.nan)` would not show the warning.

### What is the expected output? What do you see instead?

In the console, I see two `RuntimeWarnings`

## Package Versions

* Spyder: 3.2.8
* Python: 3.5.2
* Qt: 5.9.3
* PyQt: 5.9.2
* Operating System: Ubuntu 16.04

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

```
IPython >=4.0    :  6.3.1 (OK)
cython >=0.21    :  0.28.2 (OK)
jedi >=0.9.0     :  0.12.0 (OK)
nbconvert >=4.0  :  5.3.1 (OK)
numpy >=1.7      :  1.15.0.dev0+52316e3 (OK)
pandas >=0.13.1  :  None (NOK)
psutil >=0.3     :  5.4.5 (OK)
pycodestyle >=2.3:  2.4.0 (OK)
pyflakes >=0.6.0 :  1.6.0 (OK)
pygments >=2.0   :  2.2.0 (OK)
pylint >=0.25    :  1.8.4 (OK)
qtconsole >=4.2.0:  4.3.1 (OK)
rope >=0.9.4     :  0.10.7 (OK)
sphinx >=0.6.6   :  1.7.3 (OK)
sympy >=0.7.3    :  None (NOK)
```



Discussion:
Thanks for reporting. We'll try to fix this in our next release.
Yup, reproduced.

Resolving patch:
diff --git a/spyder/utils/site/sitecustomize.py b/spyder/utils/site/sitecustomize.py
--- a/spyder/utils/site/sitecustomize.py
+++ b/spyder/utils/site/sitecustomize.py
@@ -305,6 +305,21 @@ def __init__(self, *args, **kwargs):
     pass
 
 
+# =============================================================================
+# Numpy adjustments
+# =============================================================================
+try:
+    # Filter warning that appears when users have 'Show max/min'
+    # turned on and Numpy arrays contain a nan value.
+    # Fixes Issue 7063
+    # Note: It only happens in Numpy 1.14+
+    warnings.filterwarnings(action='ignore', category=RuntimeWarning,
+                            module='numpy.core._methods',
+                            message=".*invalid value encountered in.*")
+except:
+    pass
+
+
 #==============================================================================
 # Pdb adjustments
 #==============================================================================


Test patch:
diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py
--- a/spyder/app/tests/test_mainwindow.py
+++ b/spyder/app/tests/test_mainwindow.py
@@ -165,6 +165,14 @@ def main_window(request):
     else:
         CONF.set('main', 'single_instance', False)
 
+    # Get config values passed in parametrize and apply them
+    try:
+        param = request.param
+        if isinstance(param, dict) and 'spy_config' in param:
+            CONF.set(*param['spy_config'])
+    except AttributeError:
+        pass
+
     # Start the window
     window = start.main()
 
@@ -214,6 +222,37 @@ def test_calltip(main_window, qtbot):
     main_window.editor.close_file()
 
 
+@pytest.mark.slow
+@flaky(max_runs=3)
+@pytest.mark.skipif(np.__version__ < '1.14.0', reason="This only happens in Numpy 1.14+")
+@pytest.mark.parametrize('main_window', [{'spy_config': ('variable_explorer', 'minmax', True)}], indirect=True)
+def test_filter_numpy_warning(main_window, qtbot):
+    """
+    Test that we filter a warning shown when an array contains nan
+    values and the Variable Explorer option 'Show arrays min/man'
+    is on.
+
+    For issue 7063
+    """
+    shell = main_window.ipyconsole.get_current_shellwidget()
+    control = shell._control
+    qtbot.waitUntil(lambda: shell._prompt_html is not None,
+                    timeout=SHELL_TIMEOUT)
+
+    # Create an array with a nan value
+    with qtbot.waitSignal(shell.executed):
+        shell.execute('import numpy as np; A=np.full(16, np.nan)')
+
+    qtbot.wait(1000)
+
+    # Assert that no warnings are shown in the console
+    assert "warning" not in control.toPlainText()
+    assert "Warning" not in control.toPlainText()
+
+    # Restore default config value
+    CONF.set('variable_explorer', 'minmax', False)
+
+
 @pytest.mark.slow
 @flaky(max_runs=3)
 @pytest.mark.use_introspection