From e31b4d2fea982e38af0828dad8af64d55bc44b0e Mon Sep 17 00:00:00 2001 From: aschade Date: Mon, 15 Jan 2018 21:11:55 -0500 Subject: [PATCH] DOC/TST: Updated docstring to show method correctly and updated test --- doc/source/whatsnew/v0.23.0.txt | 4 ++-- pandas/core/generic.py | 2 +- pandas/core/indexes/base.py | 2 +- pandas/tests/frame/test_axis_select_reindex.py | 1 + 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/source/whatsnew/v0.23.0.txt b/doc/source/whatsnew/v0.23.0.txt index e8e14bcc43a453..7989926d28d12b 100644 --- a/doc/source/whatsnew/v0.23.0.txt +++ b/doc/source/whatsnew/v0.23.0.txt @@ -272,7 +272,7 @@ Other API Changes - :class:`IntervalIndex` and ``IntervalDtype`` no longer support categorical, object, and string subtypes (:issue:`19016`) - The default ``Timedelta`` constructor now accepts an ``ISO 8601 Duration`` string as an argument (:issue:`19040`) - ``IntervalDtype`` now returns ``True`` when compared against ``'interval'`` regardless of subtype, and ``IntervalDtype.name`` now returns ``'interval'`` regardless of subtype (:issue:`18980`) -- ``KeyError`` now raises instead of ``ValueError`` when using :meth:`drop()` to remove a non-existent element in an axis of ``Series``, ``Index``, ``DataFrame`` and ``Panel`` (:issue:`19186`) +- ``KeyError`` now raises instead of ``ValueError`` in :meth:`~DataFrame.drop`, :meth:`~Panel.drop`, :meth:`~Series.drop`, :meth:`~Index.drop` when dropping a non-existent element in the axis (:issue:`19186`) - :func:`Series.to_csv` now accepts a ``compression`` argument that works in the same way as the ``compression`` argument in :func:`DataFrame.to_csv` (:issue:`18958`) .. _whatsnew_0230.deprecations: @@ -416,7 +416,7 @@ Indexing - Bug in :func:`MultiIndex.set_labels` which would cause casting (and potentially clipping) of the new labels if the ``level`` argument is not 0 or a list like [0, 1, ... ] (:issue:`19057`) - Bug in ``str.extractall`` when there were no matches empty :class:`Index` was returned instead of appropriate :class:`MultiIndex` (:issue:`19034`) - Bug in :class:`IntervalIndex` where set operations that returned an empty ``IntervalIndex`` had the wrong dtype (:issue:`19101`) -- Bug in :func:`Index.drop()`, where no ``Exception`` is raised when dropping a non-existent element from an axis in ``Index`` (:issue:`19186`) +- Bug in :meth:`~DataFrame.drop`, :meth:`~Panel.drop`, :meth:`~Series.drop`, :meth:`~Index.drop` where no ``KeyError`` is raised when dropping a non-existent element from an axis (:issue:`19186`) - I/O diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 4ed53e36c47e54..7ffef9c8a86d79 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2809,7 +2809,7 @@ def drop(self, labels=None, axis=0, index=None, columns=None, level=None, Raises ------ KeyError - * If labels are not found in the selected axis + If none of the labels are found in the selected axis Examples -------- diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index d31cc363db0383..10c22884d7acf6 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -3764,7 +3764,7 @@ def drop(self, labels, errors='raise'): Raises ------ KeyError - * If labels are not found in the selected axis + If none of the labels are found in the selected axis """ arr_dtype = 'object' if self.dtype == 'object' else None labels = _index_labels_to_array(labels, dtype=arr_dtype) diff --git a/pandas/tests/frame/test_axis_select_reindex.py b/pandas/tests/frame/test_axis_select_reindex.py index a0a3578d96325a..28e82f75858508 100644 --- a/pandas/tests/frame/test_axis_select_reindex.py +++ b/pandas/tests/frame/test_axis_select_reindex.py @@ -1143,6 +1143,7 @@ def test_raise_on_drop_duplicate_index(self, actual): level = 0 if isinstance(actual.index, MultiIndex) else None with pytest.raises(KeyError): actual.drop('c', level=level, axis=0) + with pytest.raises(KeyError): actual.T.drop('c', level=level, axis=1) expected_no_err = actual.drop('c', axis=0, level=level, errors='ignore')