Skip to content

Possible to add missing columns? #893

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

Closed
aodj opened this issue Jul 20, 2022 · 2 comments
Closed

Possible to add missing columns? #893

aodj opened this issue Jul 20, 2022 · 2 comments
Labels
question Further information is requested

Comments

@aodj
Copy link

aodj commented Jul 20, 2022

As far as I can see from the documentation the opposite behavior exists (filtering out columns not specified in the schema) but I can't see if there's a way to add in columns that should exist but aren't.

Is there a way to accomplish this? I was wondering if it might be possible by adding to the strict flag, an option to add in missing columns, such that you could do strict: "add+filter" allowing default values to be supplied AND filtering out unnecessary columns:

schema = DataFrameSchema(
    {"this_is_a_column": Column(str)},
    {"another_column": Column(str, default="na")},
 strict='add+filter')

df = pd.DataFrame({
    "unneeded_column": ["drop", "me"],
    "this_is_a_column": ["keep", "me"]},
)

validated_df = schema.validate(df)
print(validated_df)
   this_is_a_column  another_column
0              keep              na
1                me              na

Might this be possible with the DataFrame checks?

@aodj aodj added the question Further information is requested label Jul 20, 2022
@aodj
Copy link
Author

aodj commented Jul 20, 2022

Feels similar to #687

@cosmicBboy
Copy link
Collaborator

cosmicBboy commented Jul 20, 2022

Hi @aodj looking at the two issues, it does indeed look like they're semantically the same!

The only difference is in the other issue there's an additional behavior that it's a nullable column.

I'm gonna go ahead and close this issue so we can continue the discussion in #687. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants