Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ class DataFrame(NDFrame, OpsMixin):
def transpose(self, *args, copy: _bool = ...) -> DataFrame: ...
@property
def T(self) -> DataFrame: ...
def __getattr__(self, name: str) -> Series: ...
@overload
def __getitem__(self, idx: Scalar) -> Series: ...
@overload
Expand Down Expand Up @@ -1091,17 +1092,6 @@ class DataFrame(NDFrame, OpsMixin):
def applymap(
self, func: Callable, na_action: Literal["ignore"] | None = ..., **kwargs
) -> DataFrame: ...
def append(
self,
other: DataFrame
| Series
| dict[Any, Any]
| Sequence[Scalar]
| Sequence[ListLike],
ignore_index: _bool = ...,
verify_integrity: _bool = ...,
sort: _bool = ...,
) -> DataFrame: ...
def join(
self,
other: DataFrame | Series | list[DataFrame | Series],
Expand Down
1 change: 0 additions & 1 deletion pandas-stubs/core/generic.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
self, func: Callable[..., T] | tuple[Callable[..., T], str], *args, **kwargs
) -> T: ...
def __finalize__(self, other, method=..., **kwargs) -> NDFrame: ...
def __getattr__(self, name: _str): ...
def __setattr__(self, name: _str, value) -> None: ...
@property
def values(self) -> ArrayLike: ...
Expand Down
7 changes: 1 addition & 6 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
is_copy: _bool | None = ...,
**kwargs,
) -> Series[S1]: ...
def __getattr__(self, name: str) -> S1: ...
@overload
def __getitem__(
self,
Expand Down Expand Up @@ -495,12 +496,6 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
side: Literal["left", "right"] = ...,
sorter: _ListLike | None = ...,
) -> int: ...
def append(
self,
to_append: Series | Sequence[Series],
ignore_index: _bool = ...,
verify_integrity: _bool = ...,
) -> Series[S1]: ...
@overload
def compare(
self,
Expand Down
40 changes: 23 additions & 17 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@

from pandas._typing import Scalar

from tests import check
from tests import (
TYPE_CHECKING_INVALID_USAGE,
check,
)

from pandas.io.parsers import TextFileReader

Expand Down Expand Up @@ -71,26 +74,23 @@ def test_types_any() -> None:
def test_types_append() -> None:
df = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})
df2 = pd.DataFrame({"col1": [10, 20], "col2": [30, 40]})
with pytest.warns(FutureWarning, match="The frame.append"):
res1: pd.DataFrame = df.append(df2)
with pytest.warns(FutureWarning, match="The frame.append"):
res2: pd.DataFrame = df.append([1, 2, 3])
with pytest.warns(FutureWarning, match="The frame.append"):
res3: pd.DataFrame = df.append([[1, 2, 3]])
with pytest.warns(FutureWarning, match="The frame.append"):
res4: pd.DataFrame = df.append(
if TYPE_CHECKING_INVALID_USAGE:
res1: pd.DataFrame = df.append(df2) # type: ignore[operator]
res2: pd.DataFrame = df.append([1, 2, 3]) # type: ignore[operator]
res3: pd.DataFrame = df.append([[1, 2, 3]]) # type: ignore[operator]
res4: pd.DataFrame = df.append( # type: ignore[operator]
{("a", 1): [1, 2, 3], "b": df2}, ignore_index=True
)
with pytest.warns(FutureWarning, match="The frame.append"):
res5: pd.DataFrame = df.append({1: [1, 2, 3]}, ignore_index=True)
with pytest.warns(FutureWarning, match="The frame.append"):
res6: pd.DataFrame = df.append(
res5: pd.DataFrame = df.append( # type: ignore[operator]
{1: [1, 2, 3]}, ignore_index=True
)
res6: pd.DataFrame = df.append( # type: ignore[operator]
{1: [1, 2, 3], "col2": [1, 2, 3]}, ignore_index=True
)
with pytest.warns(FutureWarning, match="The frame.append"):
res7: pd.DataFrame = df.append(pd.Series([5, 6]), ignore_index=True)
with pytest.warns(FutureWarning, match="The frame.append"):
res8: pd.DataFrame = df.append(
res7: pd.DataFrame = df.append( # type: ignore[operator]
pd.Series([5, 6]), ignore_index=True
)
res8: pd.DataFrame = df.append( # type: ignore[operator]
pd.Series([5, 6], index=["col1", "col2"]), ignore_index=True
)

Expand Down Expand Up @@ -1716,6 +1716,12 @@ def test_pos() -> None:
check(assert_type(+df, pd.DataFrame), pd.DataFrame)


def test_getattr() -> None:
# GH 261
df = pd.DataFrame({"a": [1, 2]})
check(assert_type(df.a, pd.Series), pd.Series)


def test_xs_key() -> None:
# GH 214
mi = pd.MultiIndex.from_product([[0, 1], [0, 1]], names=["foo", "bar"])
Expand Down
6 changes: 6 additions & 0 deletions tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,12 @@ def test_neg() -> None:
check(assert_type(-sr_int, "pd.Series[int]"), pd.Series, int)


def test_getattr() -> None:
# GH 261
series = pd.Series([1, 2, 3], index=["a", "b", "c"], dtype=int)
check(assert_type(series.a, int), np.integer)


def test_dtype_type() -> None:
# GH 216
s1 = pd.Series(["foo"], dtype="string")
Expand Down