|
28 | 28 |
|
29 | 29 | from pandas.core.dtypes.cast import ( |
30 | 30 | can_hold_element, |
31 | | - find_common_type, |
32 | 31 | maybe_promote, |
33 | 32 | ) |
34 | 33 | from pandas.core.dtypes.common import ( |
@@ -1067,7 +1066,13 @@ def _getitem_lowerdim(self, tup: tuple): |
1067 | 1066 |
|
1068 | 1067 | tup = self._validate_key_length(tup) |
1069 | 1068 |
|
1070 | | - for i, key in enumerate(tup): |
| 1069 | + # Reverse tuple so that we are indexing along columns before rows |
| 1070 | + # and avoid unintended dtype inference. # GH60600 |
| 1071 | + if any(isinstance(ax, MultiIndex) for ax in self.obj.axes): |
| 1072 | + enum = enumerate(tup) |
| 1073 | + else: |
| 1074 | + enum = zip(range(len(tup) - 1, -1, -1), reversed(tup)) |
| 1075 | + for i, key in enum: |
1071 | 1076 | if is_label_like(key): |
1072 | 1077 | # We don't need to check for tuples here because those are |
1073 | 1078 | # caught by the _is_nested_tuple_indexer check above. |
@@ -1095,14 +1100,7 @@ def _getitem_lowerdim(self, tup: tuple): |
1095 | 1100 | if com.is_null_slice(new_key): |
1096 | 1101 | return section |
1097 | 1102 | # This is an elided recursive call to iloc/loc |
1098 | | - out = getattr(section, self.name)[new_key] |
1099 | | - # Re-interpret dtype of out.values for loc/iloc[int, list-like]. |
1100 | | - # GH60600 |
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())) |
1105 | | - return out |
| 1103 | + return getattr(section, self.name)[new_key] |
1106 | 1104 |
|
1107 | 1105 | raise IndexingError("not applicable") |
1108 | 1106 |
|
|
0 commit comments