Skip to content

Commit cc71fde

Browse files
committed
DOC: docstrings for _validate_key
1 parent d035b52 commit cc71fde

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

pandas/core/indexing.py

+32-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
_is_unorderable_exception,
1717
_ensure_platform_int)
1818
from pandas.core.dtypes.missing import isna, _infer_fill_value
19+
from pandas.errors import AbstractMethodError
20+
from pandas.util._decorators import Appender
1921

2022
from pandas.core.index import Index, MultiIndex
2123

@@ -186,8 +188,34 @@ def __setitem__(self, key, value):
186188
indexer = self._get_setitem_indexer(key)
187189
self._setitem_with_indexer(indexer, value)
188190

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()
191219

192220
def _has_valid_tuple(self, key):
193221
""" check the key for valid keys across my indexer """
@@ -1377,6 +1405,7 @@ def __init__(self, name, obj):
13771405
DeprecationWarning, stacklevel=2)
13781406
super(_IXIndexer, self).__init__(name, obj)
13791407

1408+
@Appender(_NDFrameIndexer._validate_key.__doc__)
13801409
def _validate_key(self, key, axis):
13811410
if isinstance(key, slice):
13821411
return True
@@ -1739,6 +1768,7 @@ class _LocIndexer(_LocationIndexer):
17391768
"index is integers), listlike of labels, boolean")
17401769
_exception = KeyError
17411770

1771+
@Appender(_NDFrameIndexer._validate_key.__doc__)
17421772
def _validate_key(self, key, axis):
17431773
ax = self.obj._get_axis(axis)
17441774

0 commit comments

Comments
 (0)