Skip to content

Commit 07cef29

Browse files
authored
Export InvalidIndexError (#34570)
1 parent c482b57 commit 07cef29

22 files changed

+39
-44
lines changed

doc/source/reference/general_utility_functions.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ Exceptions and warnings
3838
errors.AccessorRegistrationWarning
3939
errors.DtypeWarning
4040
errors.EmptyDataError
41-
errors.OutOfBoundsDatetime
41+
errors.InvalidIndexError
4242
errors.MergeError
4343
errors.NullFrequencyError
4444
errors.NumbaUtilError
45+
errors.OutOfBoundsDatetime
4546
errors.ParserError
4647
errors.ParserWarning
4748
errors.PerformanceWarning

doc/source/whatsnew/v1.1.0.rst

+1-1
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

+2-8
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,
@@ -90,13 +90,7 @@
9090
from pandas.core.base import PandasObject, SelectionMixin
9191
import pandas.core.common as com
9292
from pandas.core.construction import create_series_with_explicit_dtype
93-
from pandas.core.indexes.api import (
94-
Index,
95-
InvalidIndexError,
96-
MultiIndex,
97-
RangeIndex,
98-
ensure_index,
99-
)
93+
from pandas.core.indexes.api import Index, MultiIndex, RangeIndex, ensure_index
10094
from pandas.core.indexes.datetimes import DatetimeIndex
10195
from pandas.core.indexes.period import Period, PeriodIndex
10296
import pandas.core.indexing as indexing

pandas/core/groupby/grouper.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import numpy as np
99

1010
from pandas._typing import FrameOrSeries
11+
from pandas.errors import InvalidIndexError
1112
from pandas.util._decorators import cache_readonly
1213

1314
from pandas.core.dtypes.common import (
@@ -26,7 +27,6 @@
2627
from pandas.core.groupby import ops
2728
from pandas.core.groupby.categorical import recode_for_groupby, recode_from_groupby
2829
from pandas.core.indexes.api import CategoricalIndex, Index, MultiIndex
29-
from pandas.core.indexes.base import InvalidIndexError
3030
from pandas.core.series import Series
3131

3232
from pandas.io.formats.printing import pprint_thing

pandas/core/index.py

-1
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,

pandas/core/indexes/api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
from typing import List, Set
33

44
from pandas._libs import NaT, lib
5+
from pandas.errors import InvalidIndexError
56

67
import pandas.core.common as com
78
from pandas.core.indexes.base import (
89
Index,
9-
InvalidIndexError,
1010
_new_Index,
1111
ensure_index,
1212
ensure_index_from_sequences,

pandas/core/indexes/base.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from pandas._typing import DtypeObj, Label
1717
from pandas.compat import set_function_name
1818
from pandas.compat.numpy import function as nv
19+
from pandas.errors import InvalidIndexError
1920
from pandas.util._decorators import Appender, Substitution, cache_readonly, doc
2021

2122
from pandas.core.dtypes import concat as _concat
@@ -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

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from pandas._libs.tslibs import Resolution, fields, parsing, timezones, to_offset
1010
from pandas._libs.tslibs.offsets import prefix_mapping
1111
from pandas._typing import DtypeObj, Label
12+
from pandas.errors import InvalidIndexError
1213
from pandas.util._decorators import cache_readonly, doc
1314

1415
from pandas.core.dtypes.common import (
@@ -24,7 +25,7 @@
2425

2526
from pandas.core.arrays.datetimes import DatetimeArray, tz_to_dtype
2627
import pandas.core.common as com
27-
from pandas.core.indexes.base import Index, InvalidIndexError, maybe_extract_name
28+
from pandas.core.indexes.base import Index, maybe_extract_name
2829
from pandas.core.indexes.datetimelike import DatetimeTimedeltaMixin
2930
from pandas.core.indexes.extension import inherit_names
3031
from pandas.core.tools.times import to_time

pandas/core/indexes/interval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from pandas._libs.interval import Interval, IntervalMixin, IntervalTree
1212
from pandas._libs.tslibs import Timedelta, Timestamp, to_offset
1313
from pandas._typing import AnyArrayLike, Label
14+
from pandas.errors import InvalidIndexError
1415
from pandas.util._decorators import Appender, Substitution, cache_readonly
1516
from pandas.util._exceptions import rewrite_exception
1617

@@ -44,7 +45,6 @@
4445
import pandas.core.indexes.base as ibase
4546
from pandas.core.indexes.base import (
4647
Index,
47-
InvalidIndexError,
4848
_index_shared_docs,
4949
default_pprint,
5050
ensure_index,

pandas/core/indexes/multi.py

+2-7
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 InvalidIndexError, PerformanceWarning, UnsortedIndexError
2424
from pandas.util._decorators import Appender, cache_readonly, doc
2525

2626
from pandas.core.dtypes.cast import coerce_indexer_dtype
@@ -45,12 +45,7 @@
4545
from pandas.core.arrays.categorical import factorize_from_iterables
4646
import pandas.core.common as com
4747
import pandas.core.indexes.base as ibase
48-
from pandas.core.indexes.base import (
49-
Index,
50-
InvalidIndexError,
51-
_index_shared_docs,
52-
ensure_index,
53-
)
48+
from pandas.core.indexes.base import Index, _index_shared_docs, ensure_index
5449
from pandas.core.indexes.frozen import FrozenList
5550
from pandas.core.indexes.numeric import Int64Index
5651
import pandas.core.missing as missing

pandas/core/indexes/period.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pandas._libs.tslibs import Period, Resolution
99
from pandas._libs.tslibs.parsing import DateParseError, parse_time_string
1010
from pandas._typing import DtypeObj, Label
11+
from pandas.errors import InvalidIndexError
1112
from pandas.util._decorators import Appender, cache_readonly, doc
1213

1314
from pandas.core.dtypes.common import (
@@ -32,7 +33,6 @@
3233
import pandas.core.common as com
3334
import pandas.core.indexes.base as ibase
3435
from pandas.core.indexes.base import (
35-
InvalidIndexError,
3636
_index_shared_docs,
3737
ensure_index,
3838
maybe_extract_name,

pandas/core/indexes/timedeltas.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from pandas._libs import index as libindex, lib
44
from pandas._libs.tslibs import Timedelta, to_offset
55
from pandas._typing import DtypeObj, Label
6+
from pandas.errors import InvalidIndexError
67
from pandas.util._decorators import doc
78

89
from pandas.core.dtypes.common import (
@@ -18,7 +19,7 @@
1819
from pandas.core.arrays import datetimelike as dtl
1920
from pandas.core.arrays.timedeltas import TimedeltaArray
2021
import pandas.core.common as com
21-
from pandas.core.indexes.base import Index, InvalidIndexError, maybe_extract_name
22+
from pandas.core.indexes.base import Index, maybe_extract_name
2223
from pandas.core.indexes.datetimelike import (
2324
DatetimeIndexOpsMixin,
2425
DatetimeTimedeltaMixin,

pandas/core/indexing.py

+2-2
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

+2-7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
ValueKeyFunc,
3535
)
3636
from pandas.compat.numpy import function as nv
37+
from pandas.errors import InvalidIndexError
3738
from pandas.util._decorators import Appender, Substitution, doc
3839
from pandas.util._validators import validate_bool_kwarg, validate_percentile
3940

@@ -79,13 +80,7 @@
7980
from pandas.core.generic import NDFrame
8081
from pandas.core.indexers import unpack_1tuple
8182
from pandas.core.indexes.accessors import CombinedDatetimelikeProperties
82-
from pandas.core.indexes.api import (
83-
Float64Index,
84-
Index,
85-
InvalidIndexError,
86-
MultiIndex,
87-
ensure_index,
88-
)
83+
from pandas.core.indexes.api import Float64Index, Index, MultiIndex, ensure_index
8984
import pandas.core.indexes.base as ibase
9085
from pandas.core.indexes.datetimes import DatetimeIndex
9186
from pandas.core.indexes.period import PeriodIndex

pandas/errors/__init__.py

+8
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,11 @@ 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+
209+
.. versionadded:: 1.1.0
210+
"""

pandas/tests/indexes/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66

77
from pandas._libs import iNaT
8+
from pandas.errors import InvalidIndexError
89

910
from pandas.core.dtypes.common import is_datetime64tz_dtype
1011
from pandas.core.dtypes.dtypes import CategoricalDtype
@@ -25,7 +26,6 @@
2526
isna,
2627
)
2728
import pandas._testing as tm
28-
from pandas.core.indexes.base import InvalidIndexError
2929
from pandas.core.indexes.datetimelike import DatetimeIndexOpsMixin
3030

3131

pandas/tests/indexes/datetimes/test_indexing.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
import numpy as np
44
import pytest
55

6+
from pandas.errors import InvalidIndexError
7+
68
import pandas as pd
79
from pandas import DatetimeIndex, Index, Timestamp, date_range, notna
810
import pandas._testing as tm
9-
from pandas.core.indexes.base import InvalidIndexError
1011

1112
from pandas.tseries.offsets import BDay, CDay
1213

pandas/tests/indexes/interval/test_indexing.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import numpy as np
44
import pytest
55

6+
from pandas.errors import InvalidIndexError
7+
68
from pandas import (
79
CategoricalIndex,
810
Interval,
@@ -12,7 +14,6 @@
1214
timedelta_range,
1315
)
1416
import pandas._testing as tm
15-
from pandas.core.indexes.base import InvalidIndexError
1617

1718

1819
class TestGetLoc:

pandas/tests/indexes/interval/test_interval.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import numpy as np
55
import pytest
66

7+
from pandas.errors import InvalidIndexError
8+
79
import pandas as pd
810
from pandas import (
911
Index,
@@ -19,7 +21,6 @@
1921
)
2022
import pandas._testing as tm
2123
import pandas.core.common as com
22-
from pandas.core.indexes.base import InvalidIndexError
2324

2425

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

pandas/tests/indexes/multi/test_indexing.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
import numpy as np
44
import pytest
55

6+
from pandas.errors import InvalidIndexError
7+
68
import pandas as pd
79
from pandas import Categorical, Index, MultiIndex, date_range
810
import pandas._testing as tm
9-
from pandas.core.indexes.base import InvalidIndexError
1011

1112

1213
class TestSliceLocs:

pandas/tests/indexes/period/test_indexing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66

77
from pandas._libs.tslibs import period as libperiod
8+
from pandas.errors import InvalidIndexError
89

910
import pandas as pd
1011
from pandas import (
@@ -19,7 +20,6 @@
1920
period_range,
2021
)
2122
import pandas._testing as tm
22-
from pandas.core.indexes.base import InvalidIndexError
2323

2424

2525
class TestGetItem:

pandas/tests/resample/test_period_index.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
from pandas._libs.tslibs.ccalendar import DAYS, MONTHS
99
from pandas._libs.tslibs.period import IncompatibleFrequency
10+
from pandas.errors import InvalidIndexError
1011

1112
import pandas as pd
1213
from pandas import DataFrame, Series, Timestamp
1314
import pandas._testing as tm
14-
from pandas.core.indexes.base 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)