Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
twoertwein committed Aug 3, 2023
1 parent ebcc389 commit 24d42fa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
3 changes: 2 additions & 1 deletion tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1761,7 +1761,8 @@ def test_getmultiindex_columns() -> None:
[(i, s) for i in [1] for s in df.columns.get_level_values(1)]
]
res4: pd.DataFrame = df[[df.columns[0]]]
check(assert_type(df[df.columns[0]], pd.Series), pd.Series)
column: Scalar = df.columns[0]
check(assert_type(df[column], pd.Series), pd.Series)
check(assert_type(df[li[0]], pd.Series), pd.Series)


Expand Down
20 changes: 16 additions & 4 deletions tests/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
)

from pandas._typing import Dtype # noqa: F401
from pandas._typing import Scalar

from tests import (
TYPE_CHECKING_INVALID_USAGE,
Expand Down Expand Up @@ -78,9 +77,9 @@ def test_column_getitem() -> None:
# https://github.com/microsoft/python-type-stubs/issues/199#issuecomment-1132806594
df = pd.DataFrame([[1, 2, 3]], columns=["a", "b", "c"])

column = df.columns[0]
check(assert_type(column, Scalar), str)
check(assert_type(df[column], pd.Series), pd.Series, np.int64)
columns: pd.Index[str] = df.columns
check(assert_type(columns[0], str), str)
check(assert_type(df[columns[0]], pd.Series), pd.Series, np.int64)


def test_column_contains() -> None:
Expand Down Expand Up @@ -989,3 +988,16 @@ def test_intersection() -> None:
assert_type(index.intersection([pd.Timestamp("1/1/2023")]), pd.DatetimeIndex),
pd.DatetimeIndex,
)


def test_annotate() -> None:
# GH 502
df = pd.DataFrame({"a": [1, 2]})

columns: pd.Index[str] = df.columns
for column in columns:
check(assert_type(column, str), str)

names: list[str] = list(df.columns)
for name in names:
check(assert_type(name, str), str)

0 comments on commit 24d42fa

Please sign in to comment.