|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
| 3 | +from collections.abc import Hashable |
3 | 4 | import datetime as dt
|
4 | 5 | from typing import (
|
5 | 6 | TYPE_CHECKING,
|
@@ -1433,3 +1434,23 @@ def test_multiindex_range() -> None:
|
1433 | 1434 | [range(3), pd.Series([2, 3, 5])],
|
1434 | 1435 | )
|
1435 | 1436 | check(assert_type(midx_mixed_types, pd.MultiIndex), pd.MultiIndex)
|
| 1437 | + |
| 1438 | + |
| 1439 | +def test_index_naming() -> None: |
| 1440 | + """ |
| 1441 | + Test index names type both for the getter and the setter. |
| 1442 | + The names of an index should be settable with a sequence (not str) and names |
| 1443 | + property is a list[Hashable | None] (FrozenList). |
| 1444 | + """ |
| 1445 | + df = pd.DataFrame({"a": ["a", "b", "c"], "i": [10, 11, 12]}) |
| 1446 | + |
| 1447 | + df.index.names = ["idx"] |
| 1448 | + check(assert_type(df.index.names, list[Hashable | None]), list) |
| 1449 | + df.index.names = [3] |
| 1450 | + check(assert_type(df.index.names, list[Hashable | None]), list) |
| 1451 | + df.index.names = ("idx2",) |
| 1452 | + check(assert_type(df.index.names, list[Hashable | None]), list) |
| 1453 | + df.index.names = [None] |
| 1454 | + check(assert_type(df.index.names, list[Hashable | None]), list) |
| 1455 | + df.index.names = (None,) |
| 1456 | + check(assert_type(df.index.names, list[Hashable | None]), list) |
0 commit comments