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

Issue with concat and passing a Union due to presence of checking for Iterable[None] #879

Closed
Dr-Irv opened this issue Feb 26, 2024 · 2 comments · Fixed by #880
Closed

Issue with concat and passing a Union due to presence of checking for Iterable[None] #879

Dr-Irv opened this issue Feb 26, 2024 · 2 comments · Fixed by #880
Assignees
Labels
Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Comments

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Feb 26, 2024

You are right, the example doesn't work, my bad. This example does work though, and the same question still applies.

data: pd.DataFrame | pd.Series = pd.Series()

pd.concat([pd.DataFrame(), data])

returns

error: List item 0 has incompatible type "DataFrame"; expected "None"  [list-item]
error: List item 1 has incompatible type "DataFrame | Series[Any]"; expected "None"  [list-item]

Originally posted by @tvdboom in #878 (comment)

@Dr-Irv
Copy link
Collaborator Author

Dr-Irv commented Feb 26, 2024

The above code triggers issues with pyright and mypy. Interestingly, if we remove the first overload for pd.concat that looks for Iterable[None], then the above code type checks correctly.

Going to see what @twoertwein thinks - he put that in there.

@Dr-Irv Dr-Irv added the Reshaping Concat, Merge/Join, Stack/Unstack, Explode label Feb 26, 2024
@Dr-Irv Dr-Irv changed the title You are right, the example doesn't work, my bad. This example does work though, and the same question still applies. Issue with concat and passing a Union due to presence of checking for Iterable[None] Feb 26, 2024
@twoertwein
Copy link
Member

I assumed you can only concat DataFrame and Series along axis=1. seems you can also do it for axis=0:

>>> pd.concat([pd.DataFrame([[0, 1], [2, 3]]), pd.Series([4,5])])
   0    1
0  0  1.0
1  2  3.0
0  4  NaN
1  5  NaN

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants