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

Fix init of DataFrame with empty dataset (eg:"[]") and column/schema typedefs #3353

Merged
merged 3 commits into from
May 10, 2022
Merged

Fix init of DataFrame with empty dataset (eg:"[]") and column/schema typedefs #3353

merged 3 commits into from
May 10, 2022

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented May 10, 2022

Fixes #3321; when input data is an empty sequence, construct the DataFrame using the same codepath as in the None case. Extended current test coverage to validate.

Example:

import polars as pl
pl.DataFrame( data=[], columns=[("col1",pl.Float64),("col2",pl.Float64)] )

Without fix (error):

RuntimeError: Duplicate("Column with name: '' has more than one occurrences")

With fix (empty dataframe with correct schema):

shape: (0, 2)
┌──────┬──────┐
│ col1 ┆ col2 │
│ ---  ┆ ---  │
│ f64  ┆ f64  │
╞══════╪══════╡
└──────┴──────┘

@github-actions github-actions bot added the python Related to Python Polars label May 10, 2022
@ritchie46
Copy link
Member

Thanks!

@ritchie46 ritchie46 merged commit 575bc4c into pola-rs:master May 10, 2022
@alexander-beedie alexander-beedie deleted the fix-empty-dataset-constructor branch May 10, 2022 12:29
moritzwilksch pushed a commit to moritzwilksch/polars that referenced this pull request May 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DataFrame constructor: when data is an empty list, column (str, datatype) pairs are mistaken for data
2 participants