You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the master branch of pandas.
Reproducible Example
In [20]: df=pd.DataFrame({'group': pd.Series(dtype='object'), 'str': pd.Series(dtype='object')})
In [21]: df.groupby('group').any()
---------------------------------------------------------------------------ValueErrorTraceback (mostrecentcalllast)
<ipython-input-21-d0b9fa3e2ddd>in<module>---->1df.groupby('group').any()
~/.pyenv/versions/3.8.6/envs/beam/lib/python3.8/site-packages/pandas/core/groupby/groupby.pyinany(self, skipna)
1804isTruewithinitsrespectivegroup, Falseotherwise.
1805""" -> 1806 return self._bool_agg("any", skipna) 1807 1808 @final ~/.pyenv/versions/3.8.6/envs/beam/lib/python3.8/site-packages/pandas/core/groupby/groupby.py in _bool_agg(self, val_test, skipna) 1774 return result.astype(inference, copy=False) 1775 -> 1776 return self._get_cythonized_result( 1777 libgroupby.group_any_all, 1778 numeric_only=False, ~/.pyenv/versions/3.8.6/envs/beam/lib/python3.8/site-packages/pandas/core/groupby/groupby.py in _get_cythonized_result(self, base_func, cython_dtype, numeric_only, needs_counts, needs_nullable, needs_mask, pre_processing, post_processing, **kwargs) 3383 mgr = mgr.get_numeric_data() 3384 -> 3385 res_mgr = mgr.grouped_reduce(blk_func, ignore_failures=True) 3386 3387 if not is_ser and len(res_mgr.items) != len(mgr.items): ~/.pyenv/versions/3.8.6/envs/beam/lib/python3.8/site-packages/pandas/core/internals/managers.py in grouped_reduce(self, func, ignore_failures) 1338 for sb in blk._split(): 1339 try: -> 1340 applied = sb.apply(func) 1341 except (TypeError, NotImplementedError): 1342 if not ignore_failures: ~/.pyenv/versions/3.8.6/envs/beam/lib/python3.8/site-packages/pandas/core/internals/blocks.py in apply(self, func, **kwargs) 388 one 389 """-->390result=func(self.values, **kwargs)
391392returnself._split_op_result(result)
~/.pyenv/versions/3.8.6/envs/beam/lib/python3.8/site-packages/pandas/core/groupby/groupby.pyinblk_func(values)
3342vals=values3343ifpre_processing:
->3344vals, inferences=pre_processing(vals)
33453346vals=vals.astype(cython_dtype, copy=False)
~/.pyenv/versions/3.8.6/envs/beam/lib/python3.8/site-packages/pandas/core/groupby/groupby.pyinobjs_to_bool(vals)
1752ifskipna:
1753func=np.vectorize(lambdax: bool(x) ifnotisna(x) elseTrue)
->1754vals=func(vals)
1755else:
1756vals=vals.astype(bool, copy=False)
~/.pyenv/versions/3.8.6/envs/beam/lib/python3.8/site-packages/numpy/lib/function_base.pyin__call__(self, *args, **kwargs)
2106vargs.extend([kwargs[_n] for_ninnames])
2107->2108returnself._vectorize_call(func=func, args=vargs)
21092110def_get_ufunc_and_otypes(self, func, args):
~/.pyenv/versions/3.8.6/envs/beam/lib/python3.8/site-packages/numpy/lib/function_base.pyin_vectorize_call(self, func, args)
2184res=func()
2185else:
->2186ufunc, otypes=self._get_ufunc_and_otypes(func=func, args=args)
21872188# Convert args to object arrays first ~/.pyenv/versions/3.8.6/envs/beam/lib/python3.8/site-packages/numpy/lib/function_base.pyin_get_ufunc_and_otypes(self, func, args)
2140args= [asarray(arg) forarginargs]
2141ifbuiltins.any(arg.size==0forarginargs):
->2142raiseValueError('cannot call `vectorize` on size 0 inputs '2143'unless `otypes` is set')
2144ValueError: cannotcall`vectorize`onsize0inputsunless`otypes`isset
Issue Description
Some grouped aggregations raise a ValueError (from numpy vectorization code) when operating on an empty DataFrame with an object dtype column. I've only observed this in any and all (perhaps because other aggregations drop the object column by default).
I've only observed this behavior in 1.4.0rc1. I've verified this code works fine in previous pandas versions, but I haven't tested with master.
Expected Behavior
Pandas should produce an empty result, as in previous versions.
Installed Versions
1.4.0rc1
The text was updated successfully, but these errors were encountered:
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the master branch of pandas.
Reproducible Example
Issue Description
Some grouped aggregations raise a ValueError (from numpy vectorization code) when operating on an empty DataFrame with an object dtype column. I've only observed this in
any
andall
(perhaps because other aggregations drop the object column by default).I've only observed this behavior in 1.4.0rc1. I've verified this code works fine in previous pandas versions, but I haven't tested with master.
Expected Behavior
Pandas should produce an empty result, as in previous versions.
Installed Versions
1.4.0rc1
The text was updated successfully, but these errors were encountered: