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

Can't interchange pl.DataFrame with no columns #8884

Closed
2 tasks done
honno opened this issue May 17, 2023 · 1 comment · Fixed by #9144
Closed
2 tasks done

Can't interchange pl.DataFrame with no columns #8884

honno opened this issue May 17, 2023 · 1 comment · Fixed by #9144
Assignees
Labels
bug Something isn't working python Related to Python Polars

Comments

@honno
Copy link

honno commented May 17, 2023

Polars version checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of Polars.

Issue description

One cannot interchange dataframes which contain no columns (but can if they contain even one empty column). A pretty whatever issue, but thought I'd document for posterity's sake.

Reproducible example

>>> import polars as pl
>>> pl.DataFrame({}).__dataframe__()
Traceback
    ~/anaconda3/envs/df/lib/python3.10/site-packages/polars/dataframe/frame.py:1218, in DataFrame.__dataframe__(self, nan_as_null, allow_copy)
    ->  1218 return self.to_arrow().__dataframe__(nan_as_null, allow_copy)
    ~/anaconda3/envs/df/lib/python3.10/site-packages/polars/dataframe/frame.py:1839, in DataFrame.to_arrow(self)
    ->  1839 return pa.Table.from_batches(record_batches)
    ~/anaconda3/envs/df/lib/python3.10/site-packages/pyarrow/table.pxi:3972, in pyarrow.lib.Table.from_batches()
ValueError: Must pass schema, or at least one RecordBatch
>>> pl.DataFrame({"foo": pl.Series(values=[])}).__dataframe__()
<pyarrow.interchange.dataframe._PyArrowDataFrame at 0x7fc0da125c30>

Expected behavior

>>> pl.DataFrame({}).__dataframe__()
<pyarrow.interchange.dataframe._PyArrowDataFrame>  # no error

Installed versions

>>> pl.show_versions()
--------Version info---------
Polars:      0.17.14
Index type:  UInt32
Platform:    Linux-5.19.0-41-generic-x86_64-with-glibc2.35
Python:      3.10.11 | packaged by conda-forge | (main, May 10 2023, 18:58:44) [GCC 11.3.0]

----Optional dependencies----
numpy:       1.24.3
pandas:      2.1.0.dev0+779.gc96dbb77eb
pyarrow:     12.0.0  (technically using a nightly build)
connectorx:  <not installed>
deltalake:   <not installed>
fsspec:      2023.5.0
matplotlib:  3.7.1
xlsx2csv:    <not installed>
xlsxwriter:  <not installed>
@honno honno added bug Something isn't working python Related to Python Polars labels May 17, 2023
@zundertj zundertj self-assigned this May 31, 2023
zundertj added a commit to zundertj/polars that referenced this issue May 31, 2023
No schema can be inferred from the batches, as `._df.to_arrow()` returns an empty list. `pa.Tables.from_batches()` requires a schema if no batches are passed in.

Closes pola-rs#8884.
@zundertj
Copy link
Collaborator

Thank you for reporting this, I have proposed a fix in #9144.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python Related to Python Polars
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants