Skip to content

Commit c8213da

Browse files
committed
add Hashable type to __get_item__ #592
1 parent fbc5f20 commit c8213da

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

pandas-stubs/core/frame.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ class DataFrame(NDFrame, OpsMixin):
516516
def T(self) -> DataFrame: ...
517517
def __getattr__(self, name: str) -> Series: ...
518518
@overload
519-
def __getitem__(self, idx: Scalar | tuple[Hashable, ...]) -> Series: ...
519+
def __getitem__(self, idx: Scalar | Hashable | tuple[Hashable, ...]) -> Series: ...
520520
@overload
521521
def __getitem__(self, rows: slice) -> DataFrame: ...
522522
@overload

tests/test_frame.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from collections import defaultdict
44
import csv
55
import datetime
6+
from enum import Enum
67
import io
78
import itertools
89
from pathlib import Path
@@ -160,6 +161,17 @@ def test_types_getitem() -> None:
160161
df[i]
161162

162163

164+
def test_types_getitem_with_hashable() -> None:
165+
# Testing getitem support for hashable types that are not scalar
166+
# Due to the bug in https://github.com/pandas-dev/pandas-stubs/issues/592
167+
class MyEnum(Enum):
168+
FIRST = "tayyar"
169+
SECOND = "haydar"
170+
171+
df = pd.DataFrame(data = [[12.2, 10], [8.8, 15]], columns=[MyEnum.FIRST, MyEnum.SECOND])
172+
df[MyEnum.FIRST]
173+
174+
163175
def test_slice_setitem() -> None:
164176
# Due to the bug in pandas 1.2.3(https://github.com/pandas-dev/pandas/issues/40440), this is in separate test case
165177
df = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4], 5: [6, 7]})

0 commit comments

Comments
 (0)