Skip to content

Commit 1f529ce

Browse files
committed
Fix dtype inference
1 parent c5a5de1 commit 1f529ce

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

pandas/core/indexing.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
from pandas.core.dtypes.cast import (
3030
can_hold_element,
31+
find_common_type,
3132
maybe_promote,
3233
)
3334
from pandas.core.dtypes.common import (
@@ -1095,14 +1096,12 @@ def _getitem_lowerdim(self, tup: tuple):
10951096
return section
10961097
# This is an elided recursive call to iloc/loc
10971098
out = getattr(section, self.name)[new_key]
1098-
# Re-interpret dtype of out.values for loc/iloc[int, list/slice].
1099+
# Re-interpret dtype of out.values for loc/iloc[int, list-like].
10991100
# GH60600
1100-
if (
1101-
i == 0
1102-
and isinstance(key, int)
1103-
and isinstance(new_key, (list, slice))
1104-
):
1105-
out = out.infer_objects()
1101+
if i == 0 and isinstance(key, int) and is_list_like(tup[1]):
1102+
dt = self.obj.dtypes.__getitem__(tup[1])
1103+
if len(dt) > 0:
1104+
out = out.astype(find_common_type(dt.tolist()))
11061105
return out
11071106

11081107
raise IndexingError("not applicable")

0 commit comments

Comments
 (0)