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(python): Propagate strictness in from_dicts #15344

Merged
merged 3 commits into from
Mar 27, 2024
Merged

Conversation

stinodego
Copy link
Member

@stinodego stinodego commented Mar 27, 2024

Closes #15245

Includes some minor refactoring.

@github-actions github-actions bot added fix Bug fix python Related to Python Polars labels Mar 27, 2024
@stinodego stinodego marked this pull request as ready for review March 27, 2024 21:08
let val = match d.get_item(k)? {
None => AnyValue::Null,
Some(val) => val.extract::<Wrap<AnyValue>>()?.0,
Some(val) => py_object_to_any_value(val, strict)?,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the key to the issue - calling extract on Wrap<AnyValue> defaults to strict.

@stinodego stinodego merged commit c6ba62c into main Mar 27, 2024
18 checks passed
@stinodego stinodego deleted the from-dicts-strictness branch March 27, 2024 21:21
@ruomad
Copy link

ruomad commented Apr 20, 2024

Hello, it doesn't seem to have fully fixed this problem, I still get errors either with PyDataFrame.from_dict or PyDataFrame.from_rows.
It does work as expected when constructing from columns
I've tried with 0.20.22rc1

@ruomad
Copy link

ruomad commented Apr 20, 2024

To be complete it does not throw the same error than with strict = True (in column orientation) but a more cryptic

could not append value: "" of type: str to the builder; make sure that all rows have the same schema or consider increasing `infer_schema_length`

@stinodego
Copy link
Member Author

@ruomad Could you give a code example?

@ruomad
Copy link

ruomad commented Apr 20, 2024

pl.DataFrame([{'a': 1.0, 'b': ''}], schema = {'a': pl.Float64, 'b': pl.Float64}, orient = 'row', strict = False)
pl.DataFrame([[1.0, '']], schema = {'a': pl.Float64, 'b': pl.Float64}, orient = 'row', strict = False)

both yield :

polars.exceptions.ComputeError: could not append value: "" of type: str to the builder; make sure that all rows have the same schema or consider increasing `infer_schema_length`

@stinodego
Copy link
Member Author

@ruomad right, so this has to do with empty strings probably. Could you open an issue and tag me please?

@ruomad
Copy link

ruomad commented Apr 25, 2024

Done

#15882

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

strict=False is not correctly enforced
2 participants