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

pd.concat doesn't let me mix Series and DataFrame #876

Closed
tvdboom opened this issue Feb 24, 2024 · 3 comments
Closed

pd.concat doesn't let me mix Series and DataFrame #876

tvdboom opened this issue Feb 24, 2024 · 3 comments

Comments

@tvdboom
Copy link

tvdboom commented Feb 24, 2024

Describe the bug
When trying to concat a Series to a DataFrame, mypy complains, but I see in the stubs that it should be possible (see image below). Am I doing something wrong?

image

To Reproduce

  1. Provide a minimal runnable pandas example that is not properly checked by the stubs.
  def x() -> pd.DataFrame:
   df1 = pd.Series()
   df2 = pd.DataFrame()
   return pd.concat([df1, df2])

or

  def x() -> pd.DataFrame:
   df1: pd.Series | pd.DataFrame = pd.Series()
   df2 = pd.DataFrame()
   return pd.concat([df1, df2])
  1. Indicate which type checker you are using (mypy or pyright).
    mypy
  2. Show the error message received from that type checker while checking your example.
    error: List item 0 has incompatible type "Series[Any]"; expected "DataFrame" [list-item]
    or
    error: List item 0 has incompatible type "Series[Any] | DataFrame"; expected "DataFrame" [list-item]

Please complete the following information:

  • OS: Windows
  • OS Version: 10
  • python version: 3.11
  • version of type checker: 1.8.0
  • version of installed pandas-stubs: 2.2.0.240218

Additional context
Add any other context about the problem here.

@twoertwein
Copy link
Member

This works on main

| Mapping[HashableT1, Series | DataFrame | None]
and is also tested
assert_type(pd.concat([None, series, df], axis=1), pd.DataFrame), pd.DataFrame
but is not yet released.

@tvdboom
Copy link
Author

tvdboom commented Feb 25, 2024

Not sure why Iterable[Series | DataFrame] doesn't work with a list of series and dataframes, but you are right, it works from main. Thanks. I'll wait for the release then.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Feb 25, 2024

I'm going to close this since it works on main

@Dr-Irv Dr-Irv closed this as completed Feb 25, 2024
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