-
-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: __get_item__ accepts more types than it's type signature says #592
Comments
Moved to |
Does the annotation come from pandas-stubs? |
I assume so. It definitely doesn't come from pandas itself (unless you created an empty file called py.typed inside the pandas folder). |
I see. No I definitely haven't created that file :) |
I think if we add pandas-stubs/pandas-stubs/core/frame.pyi Line 519 in fbc5f20
PR and tests welcome |
Thanks @Dr-Irv I just make a PR with a test. |
* add Hashable type to __get_item__ pandas-dev#592 * add assert_type to test_types_getitem_with_hashable * code style: formatting * remove tuple[Hashable, ...] from get_item overload1 * added more assert_type to assure other overloads are ok
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
The example code above takes an Enum as column to a DataFrame and uses that enum in
__get_item__
.It works fine, which creates an inconsistency with the signature of
__get_item__
method.Here is the signature of
__get_item__
. According to this signature, enums are not accepted as index.When you use a static type checker e.g. mypy on the code example above, it fails.
More info: https://stackoverflow.com/questions/75614405/mypy-indexing-pd-dataframe-with-an-enum-raises-no-overload-variant-error
Expected Behavior
__getitem__
's signature should be updated to support the column type itself. The column type is often not limited to primitive types. In can be custom objects as well.Installed Versions
assert '_distutils' in core.__file__, core.__file__
The text was updated successfully, but these errors were encountered: