-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
ENH: Handle conversion from Polars with pd.DataFrame #47368
Comments
we cannot depend on polars instead polars can implement thr dataframe protocol pls open an issue on that repo closing as this is out of scope |
Thanks for your comments @jreback Looking through the PR on the dataframe protocol it seems like the conversion has to be called explicitly. Could there be a check within pd.DataFrame to see if the object isn't one of the usual suspects but has the dataframe namespace then it uses that namespace to construct the pandas dataframe? |
there will be further work on this but polars would need to support this in the first place |
Cheers, thanks for replying |
@braaannigan did you finally open that issue? If so, please share the link. Thanks |
polars has already implemented it pola-rs/polars#6581 |
Thanks @MarcoGorelli |
🤔 why should it be reopened? you can do In [8]: df = pl.DataFrame({'a': [1,2,3], 'b': [4,5,6]})
In [9]: pd.api.interchange.from_dataframe(df)
Out[9]:
a b
0 1 4
1 2 5
2 3 6 |
Sorry, I may have misunderstood. pldf # a Polars dataframe
pddf = pd.DataFrame(pldf) # a Pandas dataframe Anyway, the issue remained unanswered until now.
|
pd.DataFrame(pldf) is unsupported, the answer to that was
, which polars has done 🎉 Or you can just use |
Thanks for clarifying 👍 |
While I agree that the dataframe interchange protocol is a better approach, it's worth noting that we can actually depend on polars, since we're already doing it on xarray to provide a I'm surely more in favor of removing |
Sure, just noting though that they already have In [1]: pl.from_pandas(pd.DataFrame({'a': [1,2,3]}))
Out[1]:
shape: (3, 1)
┌─────┐
│ a │
│ --- │
│ i64 │
╞═════╡
│ 1 │
│ 2 │
│ 3 │
└─────┘ which I think |
we don't rely on xarray explicitly - for a type check -1 on adding any additional even implicit dependencies -0.25 on removing xarray (this is an orthogonal library so it's pretty useful) |
Is your feature request related to a problem?
I have a Polars DataFrame
polars_df
and want to convert it to a Pandas DataFrame. However, when I call pd.DataFrame(polars_df) it transposes the polars dataframe.Describe the solution you'd like
I would like pd.DataFrame to output a Pandas DataFrame that hasn't been transposed.
API breaking implications
In the
__init__
method of the DataFrame class (line 604) it would check if the type string was polars.internal.dataframe and if so it would call theto_pandas
method of the object.Describe alternatives you've considered
In my own code I can just use the
to_pandas
method of a polars dataframe, but 3rd-party libraries do not do this.Additional context
gives output like:
so the rows have been transposed and the column names have been dropped
The text was updated successfully, but these errors were encountered: