Skip to content

update signature of Series.pop #627 #631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 7, 2023
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
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