Skip to content

REGR: fix non-reduction apply with tz-aware objects #31614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pandas/_libs/reduction.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ cdef class Reducer:
if self.typ is not None:
# In this case, we also have self.index
name = labels[i]
cached_typ = self.typ(chunk, index=self.index, name=name)
cached_typ = self.typ(
chunk, index=self.index, name=name, dtype=arr.dtype)

# use the cached_typ if possible
if cached_typ is not None:
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/frame/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,12 @@ def apply_list(row):
)
tm.assert_series_equal(result, expected)

def test_apply_noreduction_tzaware_object(self):
# https://github.com/pandas-dev/pandas/issues/31505
df = pd.DataFrame({"foo": [pd.Timestamp("2020", tz="UTC")]}, dtype="object")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would also test this w/o the col.copy(), e.g. df.apply(lambda col: col)

result = df.apply(lambda col: col.copy())
tm.assert_frame_equal(result, df)


class TestInferOutputShape:
# the user has supplied an opaque UDF where
Expand Down