|
27 | 27 | _chained_assignment_msg,
|
28 | 28 | )
|
29 | 29 | from pandas.util._decorators import doc
|
| 30 | +from pandas.util._exceptions import find_stack_level |
30 | 31 |
|
31 | 32 | from pandas.core.dtypes.cast import (
|
32 | 33 | can_hold_element,
|
@@ -869,7 +870,19 @@ def __setitem__(self, key, value) -> None:
|
869 | 870 | key = tuple(list(x) if is_iterator(x) else x for x in key)
|
870 | 871 | key = tuple(com.apply_if_callable(x, self.obj) for x in key)
|
871 | 872 | else:
|
872 |
| - key = com.apply_if_callable(key, self.obj) |
| 873 | + maybe_callable = com.apply_if_callable(key, self.obj) |
| 874 | + if ( |
| 875 | + self.name == "iloc" |
| 876 | + and callable(key) |
| 877 | + and isinstance(maybe_callable, tuple) |
| 878 | + ): |
| 879 | + warnings.warn( |
| 880 | + "Returning a tuple from a callable in iLocation indexing " |
| 881 | + "is deprecated and will be removed in a future version", |
| 882 | + FutureWarning, |
| 883 | + stacklevel=find_stack_level(), |
| 884 | + ) |
| 885 | + key = maybe_callable |
873 | 886 | indexer = self._get_setitem_indexer(key)
|
874 | 887 | self._has_valid_setitem_indexer(key)
|
875 | 888 |
|
@@ -1130,6 +1143,17 @@ def __getitem__(self, key):
|
1130 | 1143 | axis = self.axis or 0
|
1131 | 1144 |
|
1132 | 1145 | maybe_callable = com.apply_if_callable(key, self.obj)
|
| 1146 | + if ( |
| 1147 | + self.name == "iloc" |
| 1148 | + and callable(key) |
| 1149 | + and isinstance(maybe_callable, tuple) |
| 1150 | + ): |
| 1151 | + warnings.warn( |
| 1152 | + "Returning a tuple from a callable in iLocation indexing " |
| 1153 | + "is deprecated and will be removed in a future version", |
| 1154 | + FutureWarning, |
| 1155 | + stacklevel=find_stack_level(), |
| 1156 | + ) |
1133 | 1157 | return self._getitem_axis(maybe_callable, axis=axis)
|
1134 | 1158 |
|
1135 | 1159 | def _is_scalar_access(self, key: tuple):
|
|
0 commit comments