Skip to content

nested type annotation raises TypeError #1245

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

Closed
Ranfir opened this issue Jun 9, 2025 · 2 comments
Closed

nested type annotation raises TypeError #1245

Ranfir opened this issue Jun 9, 2025 · 2 comments

Comments

@Ranfir
Copy link

Ranfir commented Jun 9, 2025

This works:

from __future__ import annotations
import pandas as pd
lst: list[pd.Series[int]] = []

As does this:

from __future__ import annotations
import pandas as pd
list["pd.Series[int]"]()

But not this:

from __future__ import annotations
import pandas as pd
list[pd.Series[int]]()

TypeError: type 'Series' is not subscriptable

For what it's worth, pyarrow-stubs suffers from the same issue.

  • OS: Debian GNU/Linux 11 (bullseye)
  • python 3.13.3
  • pandas-stubs 2.2.3.250308
@loicdiridollou
Copy link
Member

Hi @Ranfir !
Thanks for the report, this is a known issue: pd.Series (when you call it in the last example) is not treated as a type that you can subscribe to but as the Series object that gets created by pandas.
It is not treated as a type the same way list[list[int]]() would be.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Jun 10, 2025

The other issue here is that the stubs have more specific types than the runtime. E.g., if you have s=pd.Series([1,2,3]), the stubs type is Series[int], but without the stubs, the type is just pd.Series. The Generic aspect of Series exists in the stubs, but not in the source, so it's not available at runtime.

Going to close - this is not something we will fix.

@Dr-Irv Dr-Irv closed this as completed Jun 10, 2025
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

No branches or pull requests

3 participants