|
16 | 16 | _is_unorderable_exception,
|
17 | 17 | _ensure_platform_int)
|
18 | 18 | from pandas.core.dtypes.missing import isna, _infer_fill_value
|
| 19 | +from pandas.errors import AbstractMethodError |
| 20 | +from pandas.util._decorators import Appender |
19 | 21 |
|
20 | 22 | from pandas.core.index import Index, MultiIndex
|
21 | 23 |
|
@@ -186,8 +188,34 @@ def __setitem__(self, key, value):
|
186 | 188 | indexer = self._get_setitem_indexer(key)
|
187 | 189 | self._setitem_with_indexer(indexer, value)
|
188 | 190 |
|
189 |
| - def _validate_key(self, k, axis): |
190 |
| - raise NotImplementedError() |
| 191 | + def _validate_key(self, key, axis): |
| 192 | + """ |
| 193 | + Ensure that key is valid for current indexer. |
| 194 | +
|
| 195 | + Parameters |
| 196 | + ---------- |
| 197 | + key : scalar, slice or list-like |
| 198 | + The key requested |
| 199 | +
|
| 200 | + axis : int |
| 201 | + Dimension on which the indexing is being made |
| 202 | +
|
| 203 | + Returns: |
| 204 | + -------- |
| 205 | + None |
| 206 | +
|
| 207 | + Raises |
| 208 | + ------ |
| 209 | + TypeError |
| 210 | + If the key (or some element of it) has wrong type |
| 211 | +
|
| 212 | + IndexError |
| 213 | + If the key (or some element of it) is out of bounds |
| 214 | +
|
| 215 | + KeyError |
| 216 | + If the key was not found |
| 217 | + """ |
| 218 | + raise AbstractMethodError() |
191 | 219 |
|
192 | 220 | def _has_valid_tuple(self, key):
|
193 | 221 | """ check the key for valid keys across my indexer """
|
@@ -1377,6 +1405,7 @@ def __init__(self, name, obj):
|
1377 | 1405 | DeprecationWarning, stacklevel=2)
|
1378 | 1406 | super(_IXIndexer, self).__init__(name, obj)
|
1379 | 1407 |
|
| 1408 | + @Appender(_NDFrameIndexer._validate_key.__doc__) |
1380 | 1409 | def _validate_key(self, key, axis):
|
1381 | 1410 | if isinstance(key, slice):
|
1382 | 1411 | return True
|
@@ -1739,6 +1768,7 @@ class _LocIndexer(_LocationIndexer):
|
1739 | 1768 | "index is integers), listlike of labels, boolean")
|
1740 | 1769 | _exception = KeyError
|
1741 | 1770 |
|
| 1771 | + @Appender(_NDFrameIndexer._validate_key.__doc__) |
1742 | 1772 | def _validate_key(self, key, axis):
|
1743 | 1773 | ax = self.obj._get_axis(axis)
|
1744 | 1774 |
|
|
0 commit comments