BUG/QST: Series.transform with a dictionary (original) (raw)

What is the expected output of passing a dictionary to Series.transform? For example:

s = pd.Series([1, 2, 3])
result1 = s.transform({'a': lambda x: x + 1})
result2 = s.transform({'a': lambda x: x + 1, 'b': lambda x: x + 2})

The docs say that dict of axis labels -> functions is acceptable, but I can't find any example in the docs where the output is described/shown. Under the hood, Series.transform is just calling Series.aggregate which produces the following outputs for result1 and result2.

# result1
a  0    2
   1    3
   2    4
dtype: int64

# result2
a  0    2
   1    3
   2    4
b  0    3
   1    4
   2    5
dtype: int64

result1 is deemed acceptable (the length of the result equals the length of the input) and is returned, but result2 raises; it is not a transformation.

I am wondering if a better return would be a DataFrame where the keys are the column names ('a' and 'b' in this example).