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): Raise suitable error when invalid column passed to get_column_index #17868

Merged
merged 2 commits into from
Jul 26, 2024

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Jul 25, 2024

Invalid column name lookups were returning None from get_column_index.

This isn't consistent with get_column or the function typing (which indicates it will only return int, or raise an error), and was discovered after tracking down a much more cryptic error at work caused by the unexpected None :)

Now raises the expected ColumnNotFoundError.
Test coverage added.

Example

df = pl.DataFrame({
  "foo": [1, 2, 3],
  "bar": [4, 5, 6],
  "ham": [7, 8, 9],
})

Column exists; returns index:

df.get_column_index("ham")
# 2

Column does not exist; raises the expected error:

df.get_column_index("sandwich")
# ColumnNotFoundError: sandwich

@github-actions github-actions bot added fix Bug fix python Related to Python Polars labels Jul 25, 2024
Copy link

codecov bot commented Jul 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.48%. Comparing base (3016c07) to head (a77f7e5).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17868      +/-   ##
==========================================
+ Coverage   80.47%   80.48%   +0.01%     
==========================================
  Files        1505     1505              
  Lines      197273   197276       +3     
  Branches     2807     2808       +1     
==========================================
+ Hits       158764   158787      +23     
+ Misses      37987    37967      -20     
  Partials      522      522              

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

Copy link
Member

@stinodego stinodego left a comment

Choose a reason for hiding this comment

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

Thanks! We should just point to try_get_column_index. See comments!

@alexander-beedie
Copy link
Collaborator Author

Thanks! We should just point to try_get_column_index. See comments!

Yup; done ;)

@ritchie46 ritchie46 merged commit 43bf944 into pola-rs:main Jul 26, 2024
17 checks passed
@alexander-beedie alexander-beedie deleted the get-column-index branch July 26, 2024 11:15
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.

4 participants