BUG: Series.groupby.sum fails because result has _values attribute but not ndim attribute
- [x] I have checked that this issue has not already been reported.

- [x] I have confirmed this bug exists on the latest version of pandas.

- [x] (optional) I have confirmed this bug exists on the master branch of pandas.

---

**Note**: Please read [this guide](https://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports) detailing how to provide the necessary information for us to reproduce your bug.

#### Code Sample, a copy-pastable example

```python
import pandas as pd

class TestClass:
    
    def __init__(self, num):
        self.num = num
        self._values = []
        
    def __add__(self, other):
        return TestClass(self.num + other.num)

s = pd.Series(
    [TestClass(1), TestClass(2), TestClass(3)],
    index=pd.Index([0,1,1], name="ind"),
)

s.sum()

s.groupby("ind").sum()
```

#### Problem description
s.sum() works but, for pandas >= 1.2.0, s.groupby("ind").sum() results in the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\rclement\tempenv\lib\site-packages\pandas\core\groupby\groupby.py", line 1654, in sum
    npfunc=np.sum,
  File "C:\Users\rclement\tempenv\lib\site-packages\pandas\core\groupby\groupby.py", line 1044, in _agg_general
    result = self.aggregate(lambda x: npfunc(x, axis=self.axis))
  File "C:\Users\rclement\tempenv\lib\site-packages\pandas\core\groupby\generic.py", line 259, in aggregate
    return self._python_agg_general(func, *args, **kwargs)
  File "C:\Users\rclement\tempenv\lib\site-packages\pandas\core\groupby\groupby.py", line 1173, in _python_agg_general
    result, counts = self.grouper.agg_series(obj, f)
  File "C:\Users\rclement\tempenv\lib\site-packages\pandas\core\groupby\ops.py", line 706, in agg_series
    return self._aggregate_series_fast(obj, func)
  File "C:\Users\rclement\tempenv\lib\site-packages\pandas\core\groupby\ops.py", line 732, in _aggregate_series_fast
    result, counts = grouper.get_result()
  File "pandas\_libs\reduction.pyx", line 260, in pandas._libs.reduction.SeriesGrouper.get_result
  File "pandas\_libs\reduction.pyx", line 77, in pandas._libs.reduction._BaseGrouper._apply_to_group
  File "pandas\_libs\reduction.pyx", line 289, in pandas._libs.reduction.extract_result
AttributeError: 'list' object has no attribute 'ndim'


The error is due to an assumption in pandas\_libs\reduction.pyx in the following function, where if the result of the sum has an attribute _values, then it is also assumed to have an attribute ndim (and the __len__ method), which is not necessarily true for user defined objects like "TestClass"

```python
cpdef inline extract_result(object res, bint squeeze=True):
    """ extract the result object, it might be a 0-dim ndarray
        or a len-1 0-dim, or a scalar """
    if hasattr(res, "_values"):
        # Preserve EA
        res = res._values
        if squeeze and res.ndim == 1 and len(res) == 1:
            res = res[0]
    if hasattr(res, 'values') and is_array(res.values):
        res = res.values
    if is_array(res):
        if res.ndim == 0:
            res = res.item()
        elif squeeze and res.ndim == 1 and len(res) == 1:
            res = res[0]
    return res
```

#### Expected Output

```python
>>> s.sum()
<__main__.TestClass object at 0x000002359C7F2C08>

>>> s.groupby("ind").sum()
ind
0    <__main__.TestClass object at 0x000002359C7F2E48>
1    <__main__.TestClass object at 0x000002359C80B788>
dtype: object
```

We could check hasattr(res, "ndim") and hasattr(res, "__len__") is True, before trying to access those attributes, but it seems like the check for _values attribute is being used as a proxy for a more concrete assumption, eg is the result a pandas object?  Could the check for _values attribute be replaced with a more explicit check?

#### Output of ``pd.show_versions()``

<details>

INSTALLED VERSIONS
------------------
commit           : 7d32926db8f7541c356066dcadabf854487738de
python           : 3.7.5.final.0
python-bits      : 64
OS               : Windows
OS-release       : 10
Version          : 10.0.18362
machine          : AMD64
processor        : Intel64 Family 6 Model 158 Stepping 10, GenuineIntel
byteorder        : little
LC_ALL           : None
LANG             : None
LOCALE           : None.None

pandas           : 1.2.2
numpy            : 1.20.1
pytz             : 2021.1
dateutil         : 2.8.1
pip              : 19.2.3
setuptools       : 41.2.0
Cython           : None
pytest           : None
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : None
IPython          : None
pandas_datareader: None
bs4              : None
bottleneck       : None
fsspec           : None
fastparquet      : None
gcsfs            : None
matplotlib       : None
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pyxlsb           : None
s3fs             : None
scipy            : None
sqlalchemy       : None
tables           : None
tabulate         : None
xarray           : None
xlrd             : None
xlwt             : None
numba            : None

</details>
