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(python!): Default to raising on out-of-bounds indices in all get/gather operations #16841

Merged
merged 2 commits into from
Jun 10, 2024

Conversation

ritchie46
Copy link
Member

@ritchie46 ritchie46 commented Jun 10, 2024

Closes #15240

The default behavior was inconsistent between get and gather operations in various places. Now all such operations will raise by default.

Pass null_on_oob=True to restore previous behavior.

Example

Before:

>>> s = pl.Series([[0, 1, 2], [0]])
>>> s.list.get(1)
shape: (2,)
Series: '' [i64]
[
        1
        null
]

After:

>>> s.list.get(1)
Traceback (most recent call last):
...
polars.exceptions.ComputeError: get index is out of bounds

Use instead:

>>> s.list.get(1, null_on_oob=True)
shape: (2,)
Series: '' [i64]
[
        1
        null
]

@github-actions github-actions bot added breaking Change that breaks backwards compatibility enhancement New feature or an improvement of an existing feature python Related to Python Polars labels Jun 10, 2024
@ritchie46 ritchie46 changed the title feat(python)!: Default to raising for oob on all get/gather operations feat(python!): Default to raising for oob on all get/gather operations Jun 10, 2024
@ritchie46 ritchie46 added breaking python Change that breaks backwards compatibility for the Python package and removed breaking Change that breaks backwards compatibility labels Jun 10, 2024
@ritchie46 ritchie46 added this to the 1.0.0 milestone Jun 10, 2024
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! Could you also add null_on_oob to Expr/Series.get/gather? Or keep the issue open for post-1.0.0?

At least the behavior is consistent now so we're set for 1.0.0 👍

@ritchie46
Copy link
Member Author

Adding the functionality can be done later. Is very low priority AFAIC.

@ritchie46
Copy link
Member Author

Added a feature request.

Copy link

codecov bot commented Jun 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.39%. Comparing base (0f1eb18) to head (34b82fe).

Current head 34b82fe differs from pull request most recent head 885f781

Please upload reports for the commit 885f781 to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16841      +/-   ##
==========================================
- Coverage   81.40%   81.39%   -0.02%     
==========================================
  Files        1425     1425              
  Lines      187627   187627              
  Branches     2702     2702              
==========================================
- Hits       152738   152717      -21     
- Misses      34393    34414      +21     
  Partials      496      496              

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

@ritchie46 ritchie46 merged commit 3a56f09 into main Jun 10, 2024
12 of 13 checks passed
@ritchie46 ritchie46 deleted the raise branch June 10, 2024 07:41
@stinodego stinodego changed the title feat(python!): Default to raising for oob on all get/gather operations feat(python!): Default to raising on out-of-bounds indices in all get/gather operations Jun 12, 2024
Wouittone pushed a commit to Wouittone/polars that referenced this pull request Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking python Change that breaks backwards compatibility for the Python package enhancement New feature or an improvement of an existing feature python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add null_on_oob on all get/gather operations
2 participants