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

feat: catch Polars exceptions, unify exception raising more #1918

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

Conversation

MarcoGorelli
Copy link
Member

@MarcoGorelli MarcoGorelli commented Feb 2, 2025

Unify exceptions, and re-raise Polars ones as Narwhals ones

This doesn't unify everything...but I think it's a nice step forwards, and should be totally backwards-compatible mostly backwards-compatible (unless anyone catches Polars exceptions specifically in tests)

Towards #1373

@MarcoGorelli MarcoGorelli changed the title unify more feat: catch Polars exceptions, unify exception raising more Feb 2, 2025
@MarcoGorelli MarcoGorelli added the enhancement New feature or request label Feb 2, 2025
@MarcoGorelli MarcoGorelli marked this pull request as ready for review February 2, 2025 19:46
@MarcoGorelli
Copy link
Member Author

The only tests failures are from Marimo, where they're checking the Polars error very tightly in their tests

        with pytest.raises(pl.exceptions.ComputeError):
            # Polars doesn't support writing nested lists to csv
>           manager.to_csv()

      with pytest.raises(pl.exceptions.ComputeError):
            # Polars doesn't support writing nested lists to csv
>           complex_data.to_csv()

@MarcoGorelli MarcoGorelli marked this pull request as draft February 2, 2025 19:50
@MarcoGorelli
Copy link
Member Author

MarcoGorelli commented Feb 2, 2025

Hey @mscolnick , I just wanted to run this past you

There's been requests to unify the exceptions from Narwhals. We do that somewhat already, but this PR makes another step towards that.

As far as I can't, there'd be no user-facing impact, it would just be matter of updating the expected exception in 2 tests from the Marimo test suite. I'd be happy to make a PR if welcome

Would you be OK with this change? Else no worries, we could always just preserve the current exceptions in the v1 API, I just figured that for something so small it might not be worth it

@mscolnick
Copy link
Contributor

Yea that is fine with us and would appreciate the help with the change, thank you!

@dangotbanned
Copy link
Contributor

@MarcoGorelli I'd be careful with how this impacts performance, since we only get zero-cost exceptions on >=3.11

Somewhat related:

@MarcoGorelli
Copy link
Member Author

MarcoGorelli commented Feb 3, 2025

Thanks Dan! I'll do some checks before shipping it - I think it shouldn't be an issue because it's only on Dataframe methods, e.g. for

df.filter(super_complicated_expression_1, super_complicated_expression_2, super_complicated_expression_3)

the try-except would only happen when filter is called, and not for each expression

Nonetheless, I would like to time it and be careful with it, so this'll stay out of today's release, we can revisit for the next one when we've done more careful checks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants