Skip to content

Commit a0f5777

Browse files
committed
Added pandas.errors.InvalidIndexError
1 parent bae7952 commit a0f5777

File tree

21 files changed

+31
-26
lines changed

21 files changed

+31
-26
lines changed

doc/source/whatsnew/v1.1.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ Other API changes
382382
- ``loc`` lookups with an object-dtype :class:`Index` and an integer key will now raise ``KeyError`` instead of ``TypeError`` when key is missing (:issue:`31905`)
383383
- Using a :func:`pandas.api.indexers.BaseIndexer` with ``count``, ``min``, ``max``, ``median``, ``skew``, ``cov``, ``corr`` will now return correct results for any monotonic :func:`pandas.api.indexers.BaseIndexer` descendant (:issue:`32865`)
384384
- Added a :func:`pandas.api.indexers.FixedForwardWindowIndexer` class to support forward-looking windows during ``rolling`` operations.
385-
-
385+
- Added :class:`pandas.errors.InvalidIndexError` (:issue:`34570`).
386386

387387
Backwards incompatible API changes
388388
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

pandas/core/generic.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
from pandas.compat import set_function_name
4848
from pandas.compat._optional import import_optional_dependency
4949
from pandas.compat.numpy import function as nv
50-
from pandas.errors import AbstractMethodError
50+
from pandas.errors import AbstractMethodError, InvalidIndexError
5151
from pandas.util._decorators import (
5252
Appender,
5353
Substitution,
@@ -92,7 +92,6 @@
9292
from pandas.core.construction import create_series_with_explicit_dtype
9393
from pandas.core.indexes.api import (
9494
Index,
95-
InvalidIndexError,
9695
MultiIndex,
9796
RangeIndex,
9897
ensure_index,

pandas/core/groupby/grouper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
from pandas.core.groupby import ops
2727
from pandas.core.groupby.categorical import recode_for_groupby, recode_from_groupby
2828
from pandas.core.indexes.api import CategoricalIndex, Index, MultiIndex
29-
from pandas.core.indexes.base import InvalidIndexError
3029
from pandas.core.series import Series
30+
from pandas.errors import InvalidIndexError
3131

3232
from pandas.io.formats.printing import pprint_thing
3333

pandas/core/index.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
Index,
88
Int64Index,
99
IntervalIndex,
10-
InvalidIndexError,
1110
MultiIndex,
1211
NaT,
1312
NumericIndex,
@@ -21,6 +20,7 @@
2120
get_objs_combined_axis,
2221
)
2322
from pandas.core.indexes.multi import _sparsify # noqa:F401
23+
from pandas.errors import InvalidIndexError
2424

2525
# GH#30193
2626
warnings.warn(
@@ -29,3 +29,5 @@
2929
FutureWarning,
3030
stacklevel=2,
3131
)
32+
33+
__all__ = ["InvalidIndexError"]

pandas/core/indexes/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import pandas.core.common as com
77
from pandas.core.indexes.base import (
88
Index,
9-
InvalidIndexError,
109
_new_Index,
1110
ensure_index,
1211
ensure_index_from_sequences,
@@ -24,6 +23,7 @@
2423
from pandas.core.indexes.period import PeriodIndex
2524
from pandas.core.indexes.range import RangeIndex
2625
from pandas.core.indexes.timedeltas import TimedeltaIndex
26+
from pandas.errors import InvalidIndexError
2727

2828
_sort_msg = textwrap.dedent(
2929
"""\

pandas/core/indexes/base.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from pandas.compat import set_function_name
1818
from pandas.compat.numpy import function as nv
1919
from pandas.util._decorators import Appender, Substitution, cache_readonly, doc
20+
from pandas.errors import InvalidIndexError
2021

2122
from pandas.core.dtypes import concat as _concat
2223
from pandas.core.dtypes.cast import (
@@ -153,10 +154,6 @@ def index_arithmetic_method(self, other):
153154
return set_function_name(index_arithmetic_method, name, cls)
154155

155156

156-
class InvalidIndexError(Exception):
157-
pass
158-
159-
160157
_o_dtype = np.dtype(object)
161158
_Identity = object
162159

pandas/core/indexes/datetimes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@
2424

2525
from pandas.core.arrays.datetimes import DatetimeArray, tz_to_dtype
2626
import pandas.core.common as com
27-
from pandas.core.indexes.base import Index, InvalidIndexError, maybe_extract_name
27+
from pandas.core.indexes.base import Index, maybe_extract_name
2828
from pandas.core.indexes.datetimelike import DatetimeTimedeltaMixin
2929
from pandas.core.indexes.extension import inherit_names
3030
from pandas.core.tools.times import to_time
31+
from pandas.errors import InvalidIndexError
3132

3233

3334
def _new_DatetimeIndex(cls, d):

pandas/core/indexes/interval.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import pandas.core.indexes.base as ibase
4545
from pandas.core.indexes.base import (
4646
Index,
47-
InvalidIndexError,
4847
_index_shared_docs,
4948
default_pprint,
5049
ensure_index,
@@ -55,6 +54,7 @@
5554
from pandas.core.indexes.multi import MultiIndex
5655
from pandas.core.indexes.timedeltas import TimedeltaIndex, timedelta_range
5756
from pandas.core.ops import get_op_result_name
57+
from pandas.errors import InvalidIndexError
5858

5959
from pandas.tseries.offsets import DateOffset
6060

pandas/core/indexes/multi.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from pandas._libs.hashtable import duplicated_int64
2121
from pandas._typing import AnyArrayLike, Scalar
2222
from pandas.compat.numpy import function as nv
23-
from pandas.errors import PerformanceWarning, UnsortedIndexError
23+
from pandas.errors import PerformanceWarning, UnsortedIndexError, InvalidIndexError
2424
from pandas.util._decorators import Appender, cache_readonly, doc
2525

2626
from pandas.core.dtypes.cast import coerce_indexer_dtype
@@ -47,7 +47,6 @@
4747
import pandas.core.indexes.base as ibase
4848
from pandas.core.indexes.base import (
4949
Index,
50-
InvalidIndexError,
5150
_index_shared_docs,
5251
ensure_index,
5352
)

pandas/core/indexes/period.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import pandas.core.common as com
3333
import pandas.core.indexes.base as ibase
3434
from pandas.core.indexes.base import (
35-
InvalidIndexError,
3635
_index_shared_docs,
3736
ensure_index,
3837
maybe_extract_name,
@@ -42,6 +41,7 @@
4241
from pandas.core.indexes.extension import inherit_names
4342
from pandas.core.indexes.numeric import Int64Index
4443
from pandas.core.ops import get_op_result_name
44+
from pandas.errors import InvalidIndexError
4545

4646
from pandas.tseries.offsets import DateOffset, Tick
4747

pandas/core/indexes/timedeltas.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
from pandas.core.arrays import datetimelike as dtl
1919
from pandas.core.arrays.timedeltas import TimedeltaArray
2020
import pandas.core.common as com
21-
from pandas.core.indexes.base import Index, InvalidIndexError, maybe_extract_name
21+
from pandas.core.indexes.base import Index, maybe_extract_name
2222
from pandas.core.indexes.datetimelike import (
2323
DatetimeIndexOpsMixin,
2424
DatetimeTimedeltaMixin,
2525
)
2626
from pandas.core.indexes.extension import inherit_names
27+
from pandas.errors import InvalidIndexError
2728

2829

2930
@inherit_names(

pandas/core/indexing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from pandas._libs.indexing import _NDFrameIndexerBase
66
from pandas._libs.lib import item_from_zerodim
7-
from pandas.errors import AbstractMethodError
7+
from pandas.errors import AbstractMethodError, InvalidIndexError
88
from pandas.util._decorators import doc
99

1010
from pandas.core.dtypes.common import (
@@ -29,7 +29,7 @@
2929
is_list_like_indexer,
3030
length_of_indexer,
3131
)
32-
from pandas.core.indexes.api import Index, InvalidIndexError
32+
from pandas.core.indexes.api import Index
3333

3434
if TYPE_CHECKING:
3535
from pandas import DataFrame # noqa:F401

pandas/core/series.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
from pandas.core.indexes.api import (
8383
Float64Index,
8484
Index,
85-
InvalidIndexError,
8685
MultiIndex,
8786
ensure_index,
8887
)
@@ -95,6 +94,7 @@
9594
from pandas.core.sorting import ensure_key_mapped
9695
from pandas.core.strings import StringMethods
9796
from pandas.core.tools.datetimes import to_datetime
97+
from pandas.errors import InvalidIndexError
9898

9999
import pandas.io.formats.format as fmt
100100
import pandas.plotting

pandas/errors/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,9 @@ class NumbaUtilError(Exception):
200200
"""
201201
Error raised for unsupported Numba engine routines.
202202
"""
203+
204+
205+
class InvalidIndexError(Exception):
206+
"""
207+
Exception raised when attemping to use an invalid index key.
208+
"""

pandas/tests/indexes/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
isna,
2626
)
2727
import pandas._testing as tm
28-
from pandas.core.indexes.base import InvalidIndexError
2928
from pandas.core.indexes.datetimelike import DatetimeIndexOpsMixin
29+
from pandas.errors import InvalidIndexError
3030

3131

3232
class Base:

pandas/tests/indexes/datetimes/test_indexing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pandas as pd
77
from pandas import DatetimeIndex, Index, Timestamp, date_range, notna
88
import pandas._testing as tm
9-
from pandas.core.indexes.base import InvalidIndexError
9+
from pandas.errors import InvalidIndexError
1010

1111
from pandas.tseries.offsets import BDay, CDay
1212

pandas/tests/indexes/interval/test_indexing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
timedelta_range,
1313
)
1414
import pandas._testing as tm
15-
from pandas.core.indexes.base import InvalidIndexError
15+
from pandas.errors import InvalidIndexError
1616

1717

1818
class TestGetLoc:

pandas/tests/indexes/interval/test_interval.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
)
2020
import pandas._testing as tm
2121
import pandas.core.common as com
22-
from pandas.core.indexes.base import InvalidIndexError
22+
from pandas.errors import InvalidIndexError
2323

2424

2525
@pytest.fixture(scope="class", params=[None, "foo"])

pandas/tests/indexes/multi/test_indexing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pandas as pd
77
from pandas import Categorical, Index, MultiIndex, date_range
88
import pandas._testing as tm
9-
from pandas.core.indexes.base import InvalidIndexError
9+
from pandas.errors import InvalidIndexError
1010

1111

1212
class TestSliceLocs:

pandas/tests/indexes/period/test_indexing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
period_range,
2020
)
2121
import pandas._testing as tm
22-
from pandas.core.indexes.base import InvalidIndexError
22+
from pandas.errors import InvalidIndexError
2323

2424

2525
class TestGetItem:

pandas/tests/resample/test_period_index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import pandas as pd
1212
from pandas import DataFrame, Series, Timestamp
1313
import pandas._testing as tm
14-
from pandas.core.indexes.base import InvalidIndexError
14+
from pandas.errors import InvalidIndexError
1515
from pandas.core.indexes.datetimes import date_range
1616
from pandas.core.indexes.period import Period, PeriodIndex, period_range
1717
from pandas.core.resample import _get_period_range_edges

0 commit comments

Comments
 (0)