Skip to content

🚸 Restrict "column 'col' not in dataframe" error to at most 10 columns #2549

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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Zethson
Copy link
Member

@Zethson Zethson commented Mar 10, 2025

Fixes #2547

Before After
ValidationError: column 'date' not in dataframe. Columns in dataframe: ['transaction_amount_usd_cent', 'currency_name', 'transaction_id', 'transaction_date', 'transaction_time', 'merchant_id', 'merchant_name', 'merchant_category', 'payment_method', 'card_type', 'card_last_four', 'customer_id', 'customer_email', 'transaction_status', 'is_recurring', 'geography_country', 'geography_city', 'device_type', 'platform', 'is_international', 'exchange_rate', 'fees_applied'] ValidationError: column 'date' not in dataframe. Found 22 columns including: 'transaction_amount_usd_cent', 'currency_name', 'transaction_id', 'transaction_date', 'transaction_time', 'merchant_id', 'merchant_name', 'merchant_category', 'payment_method', 'card_type'...

This is in line with the rest of our UX where we also only show the 10 first hits. The difference becomes bigger of course the more columns we have. I observed that a user got spammed with a stupid amount of columns for their dataset which made the whole notebook unreadable.

@Zethson Zethson changed the title ✨ Improve col not found error message 🚸 Improve col not found error message Mar 10, 2025
Copy link

codecov bot commented Mar 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.16%. Comparing base (cbe457a) to head (be56055).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2549      +/-   ##
==========================================
+ Coverage   92.15%   92.16%   +0.01%     
==========================================
  Files          60       60              
  Lines        9988    10023      +35     
==========================================
+ Hits         9204     9238      +34     
- Misses        784      785       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

github-actions bot commented Mar 11, 2025

@github-actions github-actions bot temporarily deployed to pull request March 11, 2025 10:05 Inactive
@Zethson Zethson marked this pull request as ready for review March 11, 2025 10:05
@Zethson Zethson changed the title 🚸 Improve col not found error message 🚸 Restrict "column 'col' not in dataframe" error to at most 10 columns Mar 11, 2025
@github-actions github-actions bot temporarily deployed to pull request March 11, 2025 10:46 Inactive
@Zethson Zethson requested a review from sunnyosun March 11, 2025 10:52
Copy link
Member

@sunnyosun sunnyosun left a comment

Choose a reason for hiding this comment

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

This looks so complicated and so much code, is there a way you can utilize

def _format_values(
? Which was used everywhere to truncate logging list.

@Zethson
Copy link
Member Author

Zethson commented Mar 11, 2025

@sunnyosun thank you. I don't know why I didn't think of it but it makes it much more concise.

@Zethson Zethson requested a review from sunnyosun March 11, 2025 12:09
@github-actions github-actions bot temporarily deployed to pull request March 11, 2025 12:11 Inactive
if "column" in err_msg and "not in dataframe" in err_msg:
missing_col = err_msg.split("column '")[1].split("'")[0]
display_cols_str = _format_values(
list(self._dataset.columns), n=10, quotes=True, sep="'"
Copy link
Member

Choose a reason for hiding this comment

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

Could this be simplified to display_cols_str = _format_values(self._dataset.columns, n=10)?

display_cols_str = _format_values(
list(self._dataset.columns), n=10, quotes=True, sep="'"
)
err_msg = f"column '{missing_col}' not in dataframe. {len(list(self._dataset.columns))} columns in dataframe including: {display_cols_str}"
Copy link
Member

Choose a reason for hiding this comment

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

err_msg = f"column '{missing_col}' not in dataframe. {len(list(self._dataset.columns))} columns in dataframe: {display_cols_str}"

Copy link
Member

Choose a reason for hiding this comment

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

what happens if more than 1 columns are not in dataframe?

@sunnyosun
Copy link
Member

This is OK if you need it urgently, but it's a bit patchy, we should ideally have a parser for all pandera errors.

@Zethson
Copy link
Member Author

Zethson commented Mar 11, 2025

No this is not urgent so I might revisit this at a later point with more general code.

@sunnyosun sunnyosun marked this pull request as draft March 13, 2025 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve columns not in df msg
2 participants