-
-
Notifications
You must be signed in to change notification settings - Fork 151
Open
Labels
MultiIndexgood first issuesetopsunion, intersection, difference, symmetric_differenceunion, intersection, difference, symmetric_difference
Description
Describe the bug
The methods MultiIndex.swaplevel()
and MultiIndex.union()
produce incorrect results:
swaplevel()
is missing the return type ofSelf
union
should be overridden, as the union of 2MultiIndex
should be aMultiIndex
, not anIndex
To Reproduce
from typing import reveal_type
import pandas as pd
mi = pd.MultiIndex.from_product([["a", "b"], [1, 2]], names=["let", "num"])
miswap = mi.swaplevel(0, 1)
reveal_type(miswap)
mi2= pd.MultiIndex.from_product([["a", "b"], [3, 4]], names=["let", "num"])
miu = mi.union(mi2)
reveal_type(miu)
At runtime, this produces:
Runtime type is 'MultiIndex'
Runtime type is 'MultiIndex'
With pyright
and the code currently in master
, I get:
mitest.py:6:13 - information: Type of "miswap" is "Unknown"
mitest.py:9:13 - information: Type of "miu" is "Index[Any]"
Please complete the following information:
- OS: Windows 11
- OS Version: ??
- python version 3.11
- version of type checker pyright 1.1.406
- version of installed
pandas-stubs
From commit #71b53992643d62c41d60c9903417ecc631d3e05e
Metadata
Metadata
Assignees
Labels
MultiIndexgood first issuesetopsunion, intersection, difference, symmetric_differenceunion, intersection, difference, symmetric_difference