Feature Type

  • [X] Adding new functionality to pandas

  • [ ] Changing existing functionality in pandas

  • [ ] Removing existing functionality in pandas

Problem Description

Following on from #28955, there's an issue in pint-pandas for apply with DataFrames. Ideally res would be a PintArray rather than an array of objects.

import pandas as pd
import pint
import pint_pandas
ureg = pint.get_application_registry()


def g(x):
    return x[0]
df = pd.DataFrame({'A':pd.Series([1,2,3,4], dtype='pint[day]'),'B':pd.Series([5,6,7,8], dtype='pint[day]')})
res = df.apply(g)
res

A    1 day
B    5 day
dtype: object

Feature Description

This may require the same solution as #27995. Alternatively a dtype arguement for apply.

Alternative Solutions

N/A

Additional Context

No response

Comment From: jbrockmendel

This should be feasible by making apply go through _cast_pointwise_result.