I am using the stub files provided by data-science-types to have mypy be able to check my pandas related code. Sadly I get the following behaviour:
For
import pandas as pd
def test() -> pd.DataFrame:
pass
pd.concat((test() for _ in range(10)))
mypy reports
test.py:6: error: Argument 1 to "concat" has incompatible type "Generator[DataFrame, None, None]"; expected "Union[Sequence[DataFrame], Mapping[str, DataFrame]]".
If I use pd.concat([test() for _ in range(10)])
instead mypy is happy again. Can somebody explain to me what's going on there?
Just in case it's relevant. I am using python3.8.5, pandas 1.1.2, mypy 0.782 and data-science-types 0.2.18.
First of all since the generator expression in my code has SendType and ReturnType of None so
Generator[DataFrame, None, None]
is the correct type see docs. So as chepner has pointed out the problem lies in the expected type. Even thoughpandas.concat
excepts generators data-science-types does not have it as possible input type for it. I would have considered that a bug but on their github page data-science-types they writeAnd I consider the problem solved.