Skip to content

Commit

Permalink
update signature of Series.pop pandas-dev#627
Browse files Browse the repository at this point in the history
  • Loading branch information
anilbey committed Apr 4, 2023
1 parent 5945ada commit b9596ac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
def droplevel(
self, level: Level | list[Level], axis: AxisIndex = ...
) -> DataFrame: ...
def pop(self, item: _str) -> Series[S1]: ...
def pop(self, item: Hashable) -> Any: ...
def squeeze(self, axis: AxisIndex | None = ...) -> Scalar: ...
def __abs__(self) -> Series[S1]: ...
def add_prefix(self, prefix: _str) -> Series[S1]: ...
Expand Down
16 changes: 16 additions & 0 deletions tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import datetime
from decimal import Decimal
from enum import Enum
from pathlib import Path
import re
from typing import (
Expand Down Expand Up @@ -226,6 +227,21 @@ def test_types_dropna() -> None:
assert assert_type(s.dropna(axis=0, inplace=True), None) is None


def test_pop() -> None:
# Testing pop support for hashable types
# Due to the bug in https://github.com/pandas-dev/pandas-stubs/issues/627
class MyEnum(Enum):
FIRST = "tayyar"
SECOND = "haydar"

df = pd.DataFrame(
data=[[12.2, 10], [8.8, 15]], columns=[MyEnum.FIRST, MyEnum.SECOND]
)
series = df.loc[0]
res = series.pop(MyEnum.FIRST)
check(assert_type(res, Any), float)


def test_types_fillna() -> None:
s = pd.Series([1, np.nan, np.nan, 3])
check(assert_type(s.fillna(0), pd.Series), pd.Series)
Expand Down

0 comments on commit b9596ac

Please sign in to comment.