Open
Description
Follow-up on #22762 which added _reduce
to the ExtensionArray interface and added an implementation for IntegerArray.
Currently, for that IntegerArray we special case 'sum', 'min', 'max' to make sure they return ints (because the underlying implementation can be based on a float array, depending whether there are missing values).
pandas/pandas/core/arrays/integer.py
Lines 549 to 554 in 08e2752
That basic check has the following "problem":
- Some reductions with return python integers, others will return numpy scalars. Accessing single elements also gives numpy scalars.
In [3]: pd.Series(pd.core.arrays.integer_array([1, None, 3])).mean()
Out[3]: 2.0
In [4]: type(_)
Out[4]: numpy.float64
In [5]: pd.Series(pd.core.arrays.integer_array([1, None, 3])).sum()
Out[5]: 4
In [6]: type(_)
Out[6]: int
In [7]: type(pd.Series(pd.core.arrays.integer_array([1, None, 3]))[0])
Out[7]: numpy.int64