Skip to content

Commit

Permalink
from empty pandas table (#2518)
Browse files Browse the repository at this point in the history
* from empty pandas table
  • Loading branch information
ritchie46 committed Feb 2, 2022
1 parent 78b991b commit 7933b2e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion py-polars/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion py-polars/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "py-polars"
version = "0.12.19"
version = "0.12.20"
authors = ["ritchie46 <ritchie46@gmail.com>"]
documentation = "https://pola-rs.github.io/polars/py-polars/html/reference/index.html"
edition = "2021"
Expand Down
3 changes: 3 additions & 0 deletions py-polars/polars/internals/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ def _from_pandas(
-------
DataFrame
"""
if data.shape[0] == 0:
return DataFrame([pli.Series(name, data[name]) for name in data.columns])

return cls._from_pydf(
pandas_to_pydf(
data, columns=columns, rechunk=rechunk, nan_to_none=nan_to_none
Expand Down
13 changes: 13 additions & 0 deletions py-polars/tests/test_interop.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,16 @@ def test_numpy_to_lit() -> None:
assert out == [1, 2, 3]
out = pl.select(pl.lit(np.float32(0))).to_series().to_list()
assert out == [0.0]


def test_from_empty_pandas() -> None:
pandas_df = pd.DataFrame(
{
"A": [],
"fruits": [],
}
)

polars_df = pl.from_pandas(pandas_df)
assert polars_df.columns == ["A", "fruits"]
assert polars_df.dtypes == [pl.Float64, pl.Float64]

0 comments on commit 7933b2e

Please sign in to comment.