File tree Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change 1
1
__all__ = [
2
+ "NA" ,
2
3
"Interval" ,
3
4
"NaT" ,
4
5
"NaTType" ,
15
16
# see pandas_datetime_exec in pd_datetime.c
16
17
import pandas ._libs .pandas_parser # isort: skip # type: ignore[reportUnusedImport]
17
18
import pandas ._libs .pandas_datetime # noqa: F401 # isort: skip # type: ignore[reportUnusedImport]
19
+ from pandas ._libs .missing import NA
18
20
from pandas ._libs .interval import Interval
19
21
from pandas ._libs .tslibs import (
20
22
NaT ,
Original file line number Diff line number Diff line change 26
26
)
27
27
28
28
from pandas ._libs import (
29
+ NA ,
29
30
NaT ,
30
31
algos as libalgos ,
31
32
index as libindex ,
@@ -2084,7 +2085,7 @@ def _validate_index_level(self, level) -> None:
2084
2085
verification must be done like in MultiIndex.
2085
2086
2086
2087
"""
2087
- if isinstance (level , int ) :
2088
+ if type (level ) is int :
2088
2089
if level < 0 and level != - 1 :
2089
2090
raise IndexError (
2090
2091
"Too many levels: Index has only 1 level, "
@@ -2094,10 +2095,25 @@ def _validate_index_level(self, level) -> None:
2094
2095
raise IndexError (
2095
2096
f"Too many levels: Index has only 1 level, not { level + 1 } "
2096
2097
)
2097
- elif level != self .name :
2098
- raise KeyError (
2099
- f"Requested level ({ level } ) does not match index name ({ self .name } )"
2100
- )
2098
+
2099
+ else :
2100
+ if level is NA :
2101
+ raise KeyError (
2102
+ "Requested level is pandas.NA, which is not a valid index name"
2103
+ )
2104
+ if level is NaT :
2105
+ raise KeyError (
2106
+ "Requested level is pandas.NaT, which is not a valid index name"
2107
+ )
2108
+ if isinstance (level , float ) and np .isnan (level ):
2109
+ raise KeyError (
2110
+ "Requested level is NaN, which is not a valid index name"
2111
+ )
2112
+
2113
+ if level != self .name :
2114
+ raise KeyError (
2115
+ f"Requested level ({ level } ) does not match index name ({ self .name } )"
2116
+ )
2101
2117
2102
2118
def _get_level_number (self , level ) -> int :
2103
2119
self ._validate_index_level (level )
You can’t perform that action at this time.
0 commit comments