`pd.core.frame.set_index` stubbing is not accurate
stdedos opened this issue · 5 comments
pandas-stubs/pandas-stubs/core/frame.pyi
Lines 755 to 784 in b7d23a5
#154 had the right idea, but then #151 sorta-reverted it
Is there plans to partially revert at least these lines back to what they were?
... oh. You are right 😅
e.g., for this:
"""Test `pd.set_index`."""
import pandas as pd
# Assume df is your DataFrame
data = {"Year": [2000, 2001, 2002, 2003], "Quarter": [1, 2, 3, 4], "Revenue": [200, 220, 250, 275]}
df = pd.DataFrame(data)
# Create a multi-index using Year and Quarter
df.set_index(["Year", "Quarter"], inplace=True)
# Now you can perform more complex queries
q2_revenue = df.loc[(2001, 2), "Revenue"]
print(q2_revenue) # Output: 220
print(df)
my IDE complains
... but not mypy:
$ mypy test.py
Success: no issues found in 1 source file
my IDE complains
Do you know which type checker your IDE is using?
It's PyCharm. So ... it uses a combination of "it's own stuff" and typeshed
. Which "somehow" is hardcoded and not "auto-fetched+updated".
It's PyCharm. So ... it uses a combination of "it's own stuff" and
typeshed
. Which "somehow" is hardcoded and not "auto-fetched+updated".
Note that we only test the validity of the stubs against mypy
and pyright
. I believe we have heard reports that the type checker within PyCharm has errors, as compared to those other 2 type checkers.