diff --git a/pandas/core/groupby.py b/pandas/core/groupby.py index 7b68ad67675ff..601acac20c96d 100644 --- 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 index 40f543e211f0c..12bb09e8f8a8a 100644 --- 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 diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index 59a30fc69905f..8efa140237614 100644 --- 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 index dffb303af6ae1..a70ee80aee180 100644 --- 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 index 301a7fc437fcf..7973b27601237 100644 --- 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):