Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
3df788a
BUG: Fix Index.get_level_values() mishandling of boolean, pd.NA, np.n…
whyvineet Aug 23, 2025
fe07d18
CLN: Remove redundant checks for NA, NaT, and NaN in Index class
whyvineet Aug 23, 2025
f57ddc5
CLN: Move import of NA to maintain consistent import order
whyvineet Aug 23, 2025
eca19a2
BUG: Fix Index level validation to handle integer index names correctly
whyvineet Aug 23, 2025
390f3ef
CLN: Remove unnecessary blank line and simplify condition in Index cl…
whyvineet Aug 23, 2025
629bdf9
BUG: Update Index class level validation to use lib.is_integer for ty…
whyvineet Aug 23, 2025
041994c
BUG: Enhance Index level validation to explicitly handle NA values an…
whyvineet Aug 24, 2025
d881247
BUG: Improve Index level validation to reject all NA-like values and …
whyvineet Aug 25, 2025
3e63865
BUG: Update error message for NA-like level validation to include lev…
whyvineet Aug 25, 2025
7f541de
BUG: Enhance index level validation to handle NA-like index names and…
whyvineet Aug 25, 2025
703085e
BUG: Refactor error message formatting in Index class for clarity
whyvineet Aug 25, 2025
3793317
BUG: Refactor index level validation to improve handling of NA-like v…
whyvineet Aug 25, 2025
d32d836
Merge branch 'pandas-dev:main' into main
whyvineet Oct 4, 2025
c03d480
Fix _validate_index_level to handle None values correctly and fix CRL…
whyvineet Oct 4, 2025
19832f3
Merge branch 'pandas-dev:main' into main
whyvineet Nov 9, 2025
198a309
ENH: Add validation for positional levels and improve error messages …
whyvineet Dec 7, 2025
dd0960a
Merge branch 'pandas-dev:main' into main
whyvineet Dec 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pandas/_libs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
__all__ = [
"NA",
"Interval",
"NaT",
"NaTType",
Expand All @@ -16,6 +17,7 @@
import pandas._libs.pandas_parser # isort: skip # type: ignore[reportUnusedImport]
import pandas._libs.pandas_datetime # noqa: F401 # isort: skip # type: ignore[reportUnusedImport]
from pandas._libs.interval import Interval
from pandas._libs.missing import NA
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems this change is unrelated to the rest of the PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, actually, I was trying something and forgot to undo this change. It's fixed in the latest commit.

from pandas._libs.tslibs import (
NaT,
NaTType,
Expand Down
10 changes: 8 additions & 2 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2084,7 +2084,10 @@ def _validate_index_level(self, level) -> None:
verification must be done like in MultiIndex.

"""
if isinstance(level, int):
if type(level) is int:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a simple edge case where the Index.name is also an int

Suggested change
if type(level) is int:
if type(level) is int:
if isinstance(self.name, int) and level == self.name:
return

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lib.is_integer

if isinstance(self.name, int) and level == self.name:
return

if level < 0 and level != -1:
raise IndexError(
"Too many levels: Index has only 1 level, "
Expand All @@ -2094,7 +2097,10 @@ def _validate_index_level(self, level) -> None:
raise IndexError(
f"Too many levels: Index has only 1 level, not {level + 1}"
)
elif level != self.name:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this is a better verification that validates what is expected from the documentation.

Suggested change
elif isinstance(level, str) and isinstance(self.name, str) and level != self.name:
raise KeyError(
f"Requested level ({level}) does not match index name ({self.name})"
)

elif (
isinstance(level, str) and isinstance(self.name, str) and level != self.name
):
raise KeyError(
f"Requested level ({level}) does not match index name ({self.name})"
)
Expand Down
Loading