__iter__ method of a Series should be type annotated
See original GitHub issueDescribe the bug
A type checker can not correctly resolve the return type of the __iter__
method of a pandas series.
To Reproduce
- Provide a minimal runnable
pandas
example that is not properly checked by the stubs.
from typing_extensions import reveal_type
import pandas as pd
series = pd.Series([1, 2, 3], dtype=int)
reveal_type(series) # type = Series[int]
iterable = iter(series)
reveal_type(iterable) # type = Unkown, type should be Iterable[int]
- Indicate which type checker you are using (
mypy
orpyright
).
I am using pyright 1.1.257
- Pyright message
/home/pandas_types.py:5:13 - information: Type of "series" is "Series[int]"
/home/pandas_types.py:7:13 - information: Type of "iterable" is "Unknown"
Please complete the following information:
- OS: Linux
- OS Version: Ubuntu 22.04
- python version: 3.10.4
- version of type checker 1.1.257
- version of installed
pandas-stubs
1.4.3.220704
Issue Analytics
- State:
- Created a year ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
How to tell which type annotations support __iter__ - ...
The simplest way is to resolve the FQN of the given annotation, and then retrieve the stub for the module it belongs to...
Read more >Understanding type annotation in Python
The Iterable type should be used when the function takes an iterable and iterates over it. An iterable is an object that can...
Read more >Python | Pandas Series.iteritems()
Pandas series is a One-dimensional ndarray with axis labels. The labels need not be unique but must be a hashable type.
Read more >typing — Support for type hints — Python 3.11.1 documentation
At runtime, the statement Derived = NewType('Derived', Base) will make Derived a callable that immediately returns whatever parameter you pass it. That means...
Read more >Type hints cheat sheet - mypy 0.991 documentation
This is how you declare the type of a variable age: int = 1 # You don't need to initialize a variable to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Series
does not implement__reversed__
@Dr-Irv looks like
Series
cannot be aSequence
since aSequence
needs to implement:__getitem__
__len__
__contains__
__iter__
__reversed__
index
<< Not possible sinceindex
returns theindex
and cannot beindex(loc: int)
.count
This is somewhat unfortunate but forever unchangeable I’m sure.