Skip to content

Commit ae902f6

Browse files
authored
remove append (#261)
* remove append * __getattr__ -> Series * tests * black * and isort * maybe fix win32bit issue * generic np.integer * move __getattr__
1 parent 3dc62dd commit ae902f6

File tree

5 files changed

+27
-34
lines changed

5 files changed

+27
-34
lines changed

pandas-stubs/core/frame.pyi

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ class DataFrame(NDFrame, OpsMixin):
478478
def transpose(self, *args, copy: _bool = ...) -> DataFrame: ...
479479
@property
480480
def T(self) -> DataFrame: ...
481+
def __getattr__(self, name: str) -> Series: ...
481482
@overload
482483
def __getitem__(self, idx: Scalar) -> Series: ...
483484
@overload
@@ -1091,17 +1092,6 @@ class DataFrame(NDFrame, OpsMixin):
10911092
def applymap(
10921093
self, func: Callable, na_action: Literal["ignore"] | None = ..., **kwargs
10931094
) -> DataFrame: ...
1094-
def append(
1095-
self,
1096-
other: DataFrame
1097-
| Series
1098-
| dict[Any, Any]
1099-
| Sequence[Scalar]
1100-
| Sequence[ListLike],
1101-
ignore_index: _bool = ...,
1102-
verify_integrity: _bool = ...,
1103-
sort: _bool = ...,
1104-
) -> DataFrame: ...
11051095
def join(
11061096
self,
11071097
other: DataFrame | Series | list[DataFrame | Series],

pandas-stubs/core/generic.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,6 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
361361
self, func: Callable[..., T] | tuple[Callable[..., T], str], *args, **kwargs
362362
) -> T: ...
363363
def __finalize__(self, other, method=..., **kwargs) -> NDFrame: ...
364-
def __getattr__(self, name: _str): ...
365364
def __setattr__(self, name: _str, value) -> None: ...
366365
@property
367366
def values(self) -> ArrayLike: ...

pandas-stubs/core/series.pyi

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
245245
is_copy: _bool | None = ...,
246246
**kwargs,
247247
) -> Series[S1]: ...
248+
def __getattr__(self, name: str) -> S1: ...
248249
@overload
249250
def __getitem__(
250251
self,
@@ -495,12 +496,6 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
495496
side: Literal["left", "right"] = ...,
496497
sorter: _ListLike | None = ...,
497498
) -> int: ...
498-
def append(
499-
self,
500-
to_append: Series | Sequence[Series],
501-
ignore_index: _bool = ...,
502-
verify_integrity: _bool = ...,
503-
) -> Series[S1]: ...
504499
@overload
505500
def compare(
506501
self,

tests/test_frame.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,26 +74,23 @@ def test_types_any() -> None:
7474
def test_types_append() -> None:
7575
df = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})
7676
df2 = pd.DataFrame({"col1": [10, 20], "col2": [30, 40]})
77-
with pytest.warns(FutureWarning, match="The frame.append"):
78-
res1: pd.DataFrame = df.append(df2)
79-
with pytest.warns(FutureWarning, match="The frame.append"):
80-
res2: pd.DataFrame = df.append([1, 2, 3])
81-
with pytest.warns(FutureWarning, match="The frame.append"):
82-
res3: pd.DataFrame = df.append([[1, 2, 3]])
83-
with pytest.warns(FutureWarning, match="The frame.append"):
84-
res4: pd.DataFrame = df.append(
77+
if TYPE_CHECKING_INVALID_USAGE:
78+
res1: pd.DataFrame = df.append(df2) # type: ignore[operator]
79+
res2: pd.DataFrame = df.append([1, 2, 3]) # type: ignore[operator]
80+
res3: pd.DataFrame = df.append([[1, 2, 3]]) # type: ignore[operator]
81+
res4: pd.DataFrame = df.append( # type: ignore[operator]
8582
{("a", 1): [1, 2, 3], "b": df2}, ignore_index=True
8683
)
87-
with pytest.warns(FutureWarning, match="The frame.append"):
88-
res5: pd.DataFrame = df.append({1: [1, 2, 3]}, ignore_index=True)
89-
with pytest.warns(FutureWarning, match="The frame.append"):
90-
res6: pd.DataFrame = df.append(
84+
res5: pd.DataFrame = df.append( # type: ignore[operator]
85+
{1: [1, 2, 3]}, ignore_index=True
86+
)
87+
res6: pd.DataFrame = df.append( # type: ignore[operator]
9188
{1: [1, 2, 3], "col2": [1, 2, 3]}, ignore_index=True
9289
)
93-
with pytest.warns(FutureWarning, match="The frame.append"):
94-
res7: pd.DataFrame = df.append(pd.Series([5, 6]), ignore_index=True)
95-
with pytest.warns(FutureWarning, match="The frame.append"):
96-
res8: pd.DataFrame = df.append(
90+
res7: pd.DataFrame = df.append( # type: ignore[operator]
91+
pd.Series([5, 6]), ignore_index=True
92+
)
93+
res8: pd.DataFrame = df.append( # type: ignore[operator]
9794
pd.Series([5, 6], index=["col1", "col2"]), ignore_index=True
9895
)
9996

@@ -1720,6 +1717,12 @@ def test_pos() -> None:
17201717
check(assert_type(+df, pd.DataFrame), pd.DataFrame)
17211718

17221719

1720+
def test_getattr() -> None:
1721+
# GH 261
1722+
df = pd.DataFrame({"a": [1, 2]})
1723+
check(assert_type(df.a, pd.Series), pd.Series)
1724+
1725+
17231726
def test_xs_key() -> None:
17241727
# GH 214
17251728
mi = pd.MultiIndex.from_product([[0, 1], [0, 1]], names=["foo", "bar"])

tests/test_series.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,12 @@ def test_neg() -> None:
11491149
check(assert_type(-sr_int, "pd.Series[int]"), pd.Series, int)
11501150

11511151

1152+
def test_getattr() -> None:
1153+
# GH 261
1154+
series = pd.Series([1, 2, 3], index=["a", "b", "c"], dtype=int)
1155+
check(assert_type(series.a, int), np.integer)
1156+
1157+
11521158
def test_dtype_type() -> None:
11531159
# GH 216
11541160
s1 = pd.Series(["foo"], dtype="string")

0 commit comments

Comments
 (0)