Correct me if I'm wrong, but isn't Series.agg supposed to reduce all rows to a singular value and Series.apply supposed to apply an operation to each individual row? Currently, when a function doesn't throw one of ValueError, AttributeError, TypeError, it is assumed to be a function meant for Series.apply even when passed to Series.agg.

Consider the following example:

def one_sample_t_test(r, mu_0):
    return (np.mean(r) - mu_0) / (np.std(r) / np.sqrt(len(r)))

s.agg(lambda r: one_sample_t_test(r, 0))

This generates exactly the same series as before because the function is called with individual values instead of the whole frame. When used in conjunction with another aggregator, like mean, it crashes since it can't concatenate a singular value with a series.

https://github.com/pandas-dev/pandas/blob/c293caf2e94ca50d8036d43324d05b516392eb16/pandas/core/apply.py#L1040-L1051

Why would somebody ever call Series.agg with a function that only works on singular values?

Comment From: mhriemers

Related to #49673.

Comment From: rhshadrach

Thanks for the report - I think this is a duplicate of #49673. Please comment here if you think this is not accurate and can reopen.