Skip to content

Commit b9392cb

Browse files
committed
REGR: Index.map converting tz-agnostic result to tz
1 parent 3f67301 commit b9392cb

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

pandas/core/indexes/base.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -6124,14 +6124,16 @@ def map(self, mapper, na_action: Literal["ignore"] | None = None):
61246124
# empty
61256125
dtype = self.dtype
61266126

6127-
# e.g. if we are floating and new_values is all ints, then we
6128-
# don't want to cast back to floating. But if we are UInt64
6129-
# and new_values is all ints, we want to try.
6130-
same_dtype = lib.infer_dtype(new_values, skipna=False) == self.inferred_type
6131-
if same_dtype:
6132-
new_values = maybe_cast_pointwise_result(
6133-
new_values, self.dtype, same_dtype=same_dtype
6134-
)
6127+
if self.inferred_type != "datetime64":
6128+
# e.g. if we are floating and new_values is all ints, then we
6129+
# don't want to cast back to floating. But if we are UInt64
6130+
# and new_values is all ints, we want to try.
6131+
# GH#57192 - we skip datetime64 because inference from values is reliable
6132+
same_dtype = lib.infer_dtype(new_values, skipna=False) == self.inferred_type
6133+
if same_dtype:
6134+
new_values = maybe_cast_pointwise_result(
6135+
new_values, self.dtype, same_dtype=same_dtype
6136+
)
61356137

61366138
return Index._with_infer(new_values, dtype=dtype, copy=False, name=self.name)
61376139

0 commit comments

Comments
 (0)