Repository: pandas-dev/pandas

Issue:
WARN: numpy warnings on operations
```
pandas/tests/frame/test_operators.py::TestDataFrameOperators::()::test_comparison_invalid
  /home/travis/build/pandas-dev/pandas/pandas/core/indexes/base.py:104: DeprecationWarning: elementwise == comparison failed; this will raise an error in the future.
    result = op(self.values, np.asarray(other))
  /home/travis/build/pandas-dev/pandas/pandas/core/indexes/base.py:104: DeprecationWarning: elementwise == comparison failed; this will raise an error in the future.
    result = op(self.values, np.asarray(other))
  /home/travis/build/pandas-dev/pandas/pandas/core/indexes/base.py:104: DeprecationWarning: elementwise != comparison failed; this will raise an error in the future.
    result = op(self.values, np.asarray(other))
  /home/travis/build/pandas-dev/pandas/pandas/core/indexes/base.py:104: DeprecationWarning: elementwise != comparison failed; this will raise an error in the future.
    result = op(self.values, np.asarray(other))
  /home/travis/build/pandas-dev/pandas/pandas/core/indexes/base.py:104: DeprecationWarning: elementwise == comparison failed; this will raise an error in the future.
    result = op(self.values, np.asarray(other))
  /home/travis/build/pandas-dev/pandas/pandas/core/indexes/base.py:104: DeprecationWarning: elementwise == comparison failed; this will raise an error in the future.
    result = op(self.values, np.asarray(other))
  /home/travis/build/pandas-dev/pandas/pandas/core/indexes/base.py:104: DeprecationWarning: elementwise != comparison failed; this will raise an error in the future.
    result = op(self.values, np.asarray(other))
  /home/travis/build/pandas-dev/pandas/pandas/core/indexes/base.py:104: DeprecationWarning: elementwise != comparison failed; this will raise an error in the future.
    result = op(self.values, np.asarray(other))
```

cc @jbrockmendel I think some recent changes exposed these (or they are new in numpy 1.14.1tons).

should not just catch these, rather handle intelligently. IIRC these are for a comparison of ``None``

lots of warnings that need catchng / fixing: https://travis-ci.org/pandas-dev/pandas/jobs/349648610




Discussion:

Resolving patch:
diff --git a/pandas/core/groupby.py b/pandas/core/groupby.py
--- a/pandas/core/groupby.py
+++ b/pandas/core/groupby.py
@@ -3860,7 +3860,7 @@ def count(self):
 
         mask = (ids != -1) & ~isna(val)
         ids = _ensure_platform_int(ids)
-        out = np.bincount(ids[mask], minlength=ngroups or None)
+        out = np.bincount(ids[mask], minlength=ngroups or 0)
 
         return Series(out,
                       index=self.grouper.result_index,
diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py
--- a/pandas/core/indexes/base.py
+++ b/pandas/core/indexes/base.py
@@ -99,9 +99,14 @@ def cmp_method(self, other):
             # don't pass MultiIndex
             with np.errstate(all='ignore'):
                 result = ops._comp_method_OBJECT_ARRAY(op, self.values, other)
+
         else:
-            with np.errstate(all='ignore'):
-                result = op(self.values, np.asarray(other))
+
+            # numpy will show a DeprecationWarning on invalid elementwise
+            # comparisons, this will raise in the future
+            with warnings.catch_warnings(record=True):
+                with np.errstate(all='ignore'):
+                    result = op(self.values, np.asarray(other))
 
         # technically we could support bool dtyped Index
         # for now just return the indexing array directly


Test patch:
diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py
--- a/pandas/tests/frame/test_analytics.py
+++ b/pandas/tests/frame/test_analytics.py
@@ -529,7 +529,8 @@ def wrapper(x):
         self._check_stat_op('median', wrapper, check_dates=True)
 
     def test_min(self):
-        self._check_stat_op('min', np.min, check_dates=True)
+        with warnings.catch_warnings(record=True):
+            self._check_stat_op('min', np.min, check_dates=True)
         self._check_stat_op('min', np.min, frame=self.intframe)
 
     def test_cummin(self):
@@ -579,7 +580,8 @@ def test_cummax(self):
         assert np.shape(cummax_xs) == np.shape(self.tsframe)
 
     def test_max(self):
-        self._check_stat_op('max', np.max, check_dates=True)
+        with warnings.catch_warnings(record=True):
+            self._check_stat_op('max', np.max, check_dates=True)
         self._check_stat_op('max', np.max, frame=self.intframe)
 
     def test_mad(self):
diff --git a/pandas/tests/test_nanops.py b/pandas/tests/test_nanops.py
--- a/pandas/tests/test_nanops.py
+++ b/pandas/tests/test_nanops.py
@@ -301,24 +301,6 @@ def check_funs(self, testfunc, targfunc, allow_complex=True,
                                    allow_complex=allow_complex)
             self.check_fun(testfunc, targfunc, 'arr_obj', **kwargs)
 
-    def check_funs_ddof(self,
-                        testfunc,
-                        targfunc,
-                        allow_complex=True,
-                        allow_all_nan=True,
-                        allow_str=True,
-                        allow_date=False,
-                        allow_tdelta=False,
-                        allow_obj=True, ):
-        for ddof in range(3):
-            try:
-                self.check_funs(testfunc, targfunc, allow_complex,
-                                allow_all_nan, allow_str, allow_date,
-                                allow_tdelta, allow_obj, ddof=ddof)
-            except BaseException as exc:
-                exc.args += ('ddof %s' % ddof, )
-                raise
-
     def _badobj_wrap(self, value, func, allow_complex=True, **kwargs):
         if value.dtype.kind == 'O':
             if allow_complex:
@@ -381,37 +363,46 @@ def test_nanmedian(self):
                             allow_str=False, allow_date=False,
                             allow_tdelta=True, allow_obj='convert')
 
-    def test_nanvar(self):
-        self.check_funs_ddof(nanops.nanvar, np.var, allow_complex=False,
-                             allow_str=False, allow_date=False,
-                             allow_tdelta=True, allow_obj='convert')
+    @pytest.mark.parametrize('ddof', range(3))
+    def test_nanvar(self, ddof):
+        self.check_funs(nanops.nanvar, np.var, allow_complex=False,
+                        allow_str=False, allow_date=False,
+                        allow_tdelta=True, allow_obj='convert', ddof=ddof)
 
-    def test_nanstd(self):
-        self.check_funs_ddof(nanops.nanstd, np.std, allow_complex=False,
-                             allow_str=False, allow_date=False,
-                             allow_tdelta=True, allow_obj='convert')
+    @pytest.mark.parametrize('ddof', range(3))
+    def test_nanstd(self, ddof):
+        self.check_funs(nanops.nanstd, np.std, allow_complex=False,
+                        allow_str=False, allow_date=False,
+                        allow_tdelta=True, allow_obj='convert', ddof=ddof)
 
     @td.skip_if_no('scipy', min_version='0.17.0')
-    def test_nansem(self):
+    @pytest.mark.parametrize('ddof', range(3))
+    def test_nansem(self, ddof):
         from scipy.stats import sem
         with np.errstate(invalid='ignore'):
-            self.check_funs_ddof(nanops.nansem, sem, allow_complex=False,
-                                 allow_str=False, allow_date=False,
-                                 allow_tdelta=False, allow_obj='convert')
+            self.check_funs(nanops.nansem, sem, allow_complex=False,
+                            allow_str=False, allow_date=False,
+                            allow_tdelta=False, allow_obj='convert', ddof=ddof)
 
     def _minmax_wrap(self, value, axis=None, func=None):
+
+        # numpy warns if all nan
         res = func(value, axis)
         if res.dtype.kind == 'm':
             res = np.atleast_1d(res)
         return res
 
     def test_nanmin(self):
-        func = partial(self._minmax_wrap, func=np.min)
-        self.check_funs(nanops.nanmin, func, allow_str=False, allow_obj=False)
+        with warnings.catch_warnings(record=True):
+            func = partial(self._minmax_wrap, func=np.min)
+            self.check_funs(nanops.nanmin, func,
+                            allow_str=False, allow_obj=False)
 
     def test_nanmax(self):
-        func = partial(self._minmax_wrap, func=np.max)
-        self.check_funs(nanops.nanmax, func, allow_str=False, allow_obj=False)
+        with warnings.catch_warnings(record=True):
+            func = partial(self._minmax_wrap, func=np.max)
+            self.check_funs(nanops.nanmax, func,
+                            allow_str=False, allow_obj=False)
 
     def _argminmax_wrap(self, value, axis=None, func=None):
         res = func(value, axis)
@@ -425,17 +416,15 @@ def _argminmax_wrap(self, value, axis=None, func=None):
         return res
 
     def test_nanargmax(self):
-        func = partial(self._argminmax_wrap, func=np.argmax)
-        self.check_funs(nanops.nanargmax, func, allow_str=False,
-                        allow_obj=False, allow_date=True, allow_tdelta=True)
+        with warnings.catch_warnings(record=True):
+            func = partial(self._argminmax_wrap, func=np.argmax)
+            self.check_funs(nanops.nanargmax, func,
+                            allow_str=False, allow_obj=False,
+                            allow_date=True, allow_tdelta=True)
 
     def test_nanargmin(self):
-        func = partial(self._argminmax_wrap, func=np.argmin)
-        if tm.sys.version_info[0:2] == (2, 6):
-            self.check_funs(nanops.nanargmin, func, allow_date=True,
-                            allow_tdelta=True, allow_str=False,
-                            allow_obj=False)
-        else:
+        with warnings.catch_warnings(record=True):
+            func = partial(self._argminmax_wrap, func=np.argmin)
             self.check_funs(nanops.nanargmin, func, allow_str=False,
                             allow_obj=False)
 
diff --git a/pandas/tests/test_panel.py b/pandas/tests/test_panel.py
--- a/pandas/tests/test_panel.py
+++ b/pandas/tests/test_panel.py
@@ -100,10 +100,12 @@ def wrapper(x):
         self._check_stat_op('median', wrapper)
 
     def test_min(self):
-        self._check_stat_op('min', np.min)
+        with catch_warnings(record=True):
+            self._check_stat_op('min', np.min)
 
     def test_max(self):
-        self._check_stat_op('max', np.max)
+        with catch_warnings(record=True):
+            self._check_stat_op('max', np.max)
 
     @td.skip_if_no_scipy
     def test_skew(self):