-
-
Notifications
You must be signed in to change notification settings - Fork 154
Closed
Labels
IndexingRelated to indexing on series/frames, not to indexes themselvesRelated to indexing on series/frames, not to indexes themselvesgood first issue
Description
Describe the bug
It should be type-safe to put Series.name into DataFrame.__getitem__, but Series.name is defined as None | Hashable and DataFrame.__getitem__ does not accept Hashable.
pandas-stubs/pandas-stubs/core/frame.pyi
Lines 510 to 523 in d2e3f74
| @overload | |
| def __getitem__(self, idx: Scalar | tuple[Hashable, ...]) -> Series: ... | |
| @overload | |
| def __getitem__(self, rows: slice) -> DataFrame: ... | |
| @overload | |
| def __getitem__( | |
| self, | |
| idx: Series[_bool] | |
| | DataFrame | |
| | Index | |
| | np_ndarray_str | |
| | np_ndarray_bool | |
| | list[_ScalarOrTupleT], | |
| ) -> DataFrame: ... |
pandas-stubs/pandas-stubs/core/series.pyi
Lines 326 to 327 in d2e3f74
| @property | |
| def name(self) -> Hashable | None: ... |
To Reproduce
from pandas import DataFrame, Series
foo = Series([1, 2, 3], name="foo")
bar = DataFrame(columns=["foo", "bar", "baz"])
bar[foo.name] # [call-overload]
# No overload variant of "__getitem__" of "DataFrame" matches argument type "Hashable" Please complete the following information:
- pandas 1.5.3
- pandas-stubs 1.5.3.230304
Metadata
Metadata
Assignees
Labels
IndexingRelated to indexing on series/frames, not to indexes themselvesRelated to indexing on series/frames, not to indexes themselvesgood first issue