Skip to content

Commit

Permalink
update signature of Series.pop #627 (#631)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
anilbey authored Apr 7, 2023
1 parent f4c3721 commit 53a1e9a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 0 additions & 1 deletion pandas-stubs/core/generic.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
self, axis1: AxisIndex, axis2: AxisIndex, copy: _bool = ...
) -> NDFrame: ...
def droplevel(self, level: Level, axis: AxisIndex = ...) -> NDFrame: ...
def pop(self, item: _str) -> NDFrame: ...
def squeeze(self, axis=...): ...
def equals(self, other: Series[S1]) -> _bool: ...
def __neg__(self: NDFrameT) -> NDFrameT: ...
Expand Down
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) -> S1: ...
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"

s = pd.Series([3.2, 4.3], index=[MyEnum.FIRST, MyEnum.SECOND], dtype=float)
res = s.pop(MyEnum.FIRST)
check(assert_type(res, float), np.float64)

s2 = pd.Series([3, 5], index=["alibaba", "zuhuratbaba"], dtype=int)
check(assert_type(s2.pop("alibaba"), int), np.int_)


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 53a1e9a

Please sign in to comment.