def _try_cast(self, result, obj):
        if obj.ndim > 1:
            dtype = obj.values.dtype
        else:
            dtype = obj.dtype

        if not lib.isscalar(result):
            result = _possibly_downcast_to_dtype(result, dtype)

        return result
try to cast the result to our obj original type,
dataset/ETHPy150Open pydata/pandas/pandas/core/groupby.py/_GroupBy._try_cast