|
3 | 3 | from collections import defaultdict
|
4 | 4 | import csv
|
5 | 5 | import datetime
|
| 6 | +from enum import Enum |
6 | 7 | import io
|
7 | 8 | import itertools
|
8 | 9 | from pathlib import Path
|
@@ -160,6 +161,26 @@ def test_types_getitem() -> None:
|
160 | 161 | df[i]
|
161 | 162 |
|
162 | 163 |
|
| 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( |
| 172 | + data=[[12.2, 10], [8.8, 15]], columns=[MyEnum.FIRST, MyEnum.SECOND] |
| 173 | + ) |
| 174 | + check(assert_type(df[MyEnum.FIRST], pd.Series), pd.Series) |
| 175 | + check(assert_type(df[1:], pd.DataFrame), pd.DataFrame) |
| 176 | + check(assert_type(df[:2], pd.DataFrame), pd.DataFrame) |
| 177 | + |
| 178 | + df2 = pd.DataFrame(data=[[12.2, 10], [8.8, 15]], columns=[3, 4]) |
| 179 | + check(assert_type(df2[3], pd.Series), pd.Series) |
| 180 | + check(assert_type(df2[[3]], pd.DataFrame), pd.DataFrame) |
| 181 | + check(assert_type(df2[[3, 4]], pd.DataFrame), pd.DataFrame) |
| 182 | + |
| 183 | + |
163 | 184 | def test_slice_setitem() -> None:
|
164 | 185 | # Due to the bug in pandas 1.2.3(https://github.com/pandas-dev/pandas/issues/40440), this is in separate test case
|
165 | 186 | df = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4], 5: [6, 7]})
|
|
0 commit comments