Skip to content

Commit 53a1e9a

Browse files
authored
update signature of Series.pop #627 (#631)
* update signature of Series.pop #627 * change return type of Series.pop to S1 * create series directly in test_pop * delete pop from generic.pyi * add one more test for string index int dtype * replace np.int64 with np.int_ for windows
1 parent f4c3721 commit 53a1e9a

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

pandas-stubs/core/generic.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
7777
self, axis1: AxisIndex, axis2: AxisIndex, copy: _bool = ...
7878
) -> NDFrame: ...
7979
def droplevel(self, level: Level, axis: AxisIndex = ...) -> NDFrame: ...
80-
def pop(self, item: _str) -> NDFrame: ...
8180
def squeeze(self, axis=...): ...
8281
def equals(self, other: Series[S1]) -> _bool: ...
8382
def __neg__(self: NDFrameT) -> NDFrameT: ...

pandas-stubs/core/series.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
10211021
def droplevel(
10221022
self, level: Level | list[Level], axis: AxisIndex = ...
10231023
) -> DataFrame: ...
1024-
def pop(self, item: _str) -> Series[S1]: ...
1024+
def pop(self, item: Hashable) -> S1: ...
10251025
def squeeze(self, axis: AxisIndex | None = ...) -> Scalar: ...
10261026
def __abs__(self) -> Series[S1]: ...
10271027
def add_prefix(self, prefix: _str) -> Series[S1]: ...

tests/test_series.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import datetime
44
from decimal import Decimal
5+
from enum import Enum
56
from pathlib import Path
67
import re
78
from typing import (
@@ -226,6 +227,21 @@ def test_types_dropna() -> None:
226227
assert assert_type(s.dropna(axis=0, inplace=True), None) is None
227228

228229

230+
def test_pop() -> None:
231+
# Testing pop support for hashable types
232+
# Due to the bug in https://github.com/pandas-dev/pandas-stubs/issues/627
233+
class MyEnum(Enum):
234+
FIRST = "tayyar"
235+
SECOND = "haydar"
236+
237+
s = pd.Series([3.2, 4.3], index=[MyEnum.FIRST, MyEnum.SECOND], dtype=float)
238+
res = s.pop(MyEnum.FIRST)
239+
check(assert_type(res, float), np.float64)
240+
241+
s2 = pd.Series([3, 5], index=["alibaba", "zuhuratbaba"], dtype=int)
242+
check(assert_type(s2.pop("alibaba"), int), np.int_)
243+
244+
229245
def test_types_fillna() -> None:
230246
s = pd.Series([1, np.nan, np.nan, 3])
231247
check(assert_type(s.fillna(0), pd.Series), pd.Series)

0 commit comments

Comments
 (0)