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

Adding missing columns with a string default #1658

Open
2 of 3 tasks
ymiftah opened this issue May 27, 2024 · 0 comments
Open
2 of 3 tasks

Adding missing columns with a string default #1658

ymiftah opened this issue May 27, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ymiftah
Copy link

ymiftah commented May 27, 2024

Describe the bug
When defining a schema with a default value of string type, and enforcing auto-addition of the columns (add_missing_columns=True), the validation fails.

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of pandera.
  • (optional) I have confirmed this bug exists on the main branch of pandera.

Code Sample, a copy-pastable example

# Your code here
import polars as pl
import pandera.polars as pa

schema = pa.DataFrameSchema(
    columns={
        "a": pa.Column(int),
        "b": pa.Column(float, default=1),
        "c": pa.Column(str, default="foo"),
        "d": pa.Column(float, nullable=True),
    },
    add_missing_columns=True,
    coerce=True,
)
df = pl.DataFrame({"a": [1, 2, 3]})
schema.validate(df)

The above throws the following error

ColumnNotFoundError: foo

This error occurred with the following context stack:
	[1] 'with_columns' failed
	[2] 'with_columns' input failed to resolve
	[3] 'select' input failed to resolve
	[4] 'with_columns' input failed to resolve

Expected behavior

The column "c" should be defaulted to "foo" after validation.

Desktop (please complete the following information):

  • OS: Ubuntu
  • Browser: NA
  • Version: NA

name = "polars"
version = "0.20.30"

name = "pandera"
version = "0.19.3"

@ymiftah ymiftah added the bug Something isn't working label May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant