Skip to content
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

BUG: series.pop accepts more types than it's type signature says #627

Closed
anilbey opened this issue Apr 4, 2023 · 6 comments · Fixed by #631
Closed

BUG: series.pop accepts more types than it's type signature says #627

anilbey opened this issue Apr 4, 2023 · 6 comments · Fixed by #631

Comments

@anilbey
Copy link
Contributor

anilbey commented Apr 4, 2023

Describe the bug
Similar to #592, Series.pop also works on Hashable types but the signature does not mention them:

def pop(self, item: _str) -> Series[S1]: ...

To Reproduce

Here is the code. Running it works fine.

from enum import Enum
import pandas as pd

class MyEnum(Enum):
    TAYYAR = "tayyar"
    HAYDAR = "haydar"

df = pd.DataFrame(data = [[12.2, 10], [8.8, 15], [22.1, 14]], columns=[MyEnum.TAYYAR, MyEnum.HAYDAR])
series = df.loc[0]
print(series.pop(MyEnum.TAYYAR))

Calling it with mypy gives the following error.

error: Argument 1 to "pop" of "Series" has incompatible type "MyEnum"; expected "str"  [arg-type]

Please complete the following information:

  • OS: linux
  • python version: 3.9
  • version of type checker: mypy 1.1.1
  • version of installed pandas-stubs: pandas-stubs 1.5.3.230321
@anilbey
Copy link
Contributor Author

anilbey commented Apr 4, 2023

Similar to #596, shall I create a PR to add Hashable to its signature and provide the tests?

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Apr 4, 2023

Similar to #596, shall I create a PR to add Hashable to its signature and provide the tests?

Yes. Thanks!

anilbey added a commit to anilbey/pandas-stubs that referenced this issue Apr 4, 2023
anilbey added a commit to anilbey/pandas-stubs that referenced this issue Apr 6, 2023
Dr-Irv pushed a commit that referenced this issue Apr 7, 2023
* 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
@anilbey
Copy link
Contributor Author

anilbey commented Apr 11, 2023

@Dr-Irv if possible, could you make a new release on pypi with this change?

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Apr 11, 2023

@Dr-Irv if possible, could you make a new release on pypi with this change?

The plan is to put in the changes described in #624 and then do a 2.0.0.yymmdd release. That will depend on getting the 2.0 changes into the stubs.

I may need to alter that plan, since recent PR's have fixed things for 1.5.3.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Apr 12, 2023

@anilbey just released 2.0.0.230412 . Doesn't support all the new features of 2.0, but has the fix you provided.

@anilbey
Copy link
Contributor Author

anilbey commented Apr 13, 2023

Brilliant, thanks @Dr-Irv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants