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

Error: "Object of type Series[Unknown] is not callable" on groupby().size().to_frame() #886

Closed
tvannahl opened this issue Mar 5, 2024 · 1 comment
Labels
duplicate This issue or pull request already exists

Comments

@tvannahl
Copy link

tvannahl commented Mar 5, 2024

Describe the bug
Calling to_frame() on a groupby().size() object causes the reportCallIssue: error: Object of type "Series[Unknown]" is not callable

To Reproduce

Minimal example:

import pandas as pd

data = [
    {"date": "2023-12-01", "val": 12},
    {"date": "2023-12-02", "val": 2},
    {"date": "2023-12-03", "val": 1},
    {"date": "2023-12-03", "val": 10},
]

df = pd.DataFrame(data)
groupby = df.groupby("date")
size = groupby.size()
frame = size.to_frame()
d = frame.reset_index()

Checking:

$ pyright test.py
test.py:14:9 - error: Object of type "Series[Unknown]" is not callable (reportCallIssue)

Please complete the following information:

  • OS: MacOS
  • OS Version: 14.3.1
  • python version: 3.12.2
  • version of type checker: 1.1.352
  • version of installed pandas-stubs: 2.2.0.240218

Additional context

Issues was not present in pandas-stubs 2.1.4.231227 with pyright 1.1.348

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Mar 5, 2024

The error message here is a bit misleading, but the issue happens because the result of size() is a DataFrame or Series, dependent on whether the parameter as_index is False or True, respectively. So we'd need to update the stubs to know whether as_index=False was passed in order to be able to type this correctly.

Closing as it is a duplicate of #652 and related to #203

@Dr-Irv Dr-Irv closed this as completed Mar 5, 2024
@Dr-Irv Dr-Irv added the duplicate This issue or pull request already exists label Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants