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

int_ranges: PanicException and InvalidOperationError #11891

Closed
2 tasks done
Julian-J-S opened this issue Oct 20, 2023 · 3 comments · Fixed by #12548
Closed
2 tasks done

int_ranges: PanicException and InvalidOperationError #11891

Julian-J-S opened this issue Oct 20, 2023 · 3 comments · Fixed by #12548
Labels
bug Something isn't working python Related to Python Polars

Comments

@Julian-J-S
Copy link
Contributor

Checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

(
    pl.DataFrame({
        'asc': [1, 2, 3],
        'desc': [3, 2, 1],
        'zero': [0, 0, 0],
        'one': [1, 1, 1],
        'two': [2, 2, 2],
    })
    .with_columns(
        zero_asc=pl.int_ranges(start='zero', end='asc'),
        zero_desc=pl.int_ranges(start='zero', end='desc'),

        asc_desc=pl.int_ranges(start='asc', end='desc'),
        desc_asc=pl.int_ranges(start='desc', end='asc'),

        asc_two=pl.int_ranges(start='asc', end='two'),

        # <<< InvalidOperationError: range must be decreasing if 'step' is negative >>>
        # asc_desc_down=pl.int_ranges(start='asc', end='desc', step=-1),
        # desc_asc_down=pl.int_ranges(start='desc', end='asc', step=-1),

        # <<< # PanicException: capacity overflow; [thread '<unnamed>' panicked at library/alloc/src/raw_vec.rs:534:5:] >>>
        # asc_zero_down=pl.int_ranges(start='asc', end='zero', step=-1),
        # asc_one=pl.int_ranges(start='asc', end='one'),
    )
)
┌─────┬──────┬──────┬─────┬───┬───────────┬───────────┬───────────┬───────────┐
│ ascdesczeroone ┆ … ┆ zero_descasc_descdesc_ascasc_two   │
│ ------------ ┆   ┆ ------------       │
│ i64i64i64i64 ┆   ┆ list[i64] ┆ list[i64] ┆ list[i64] ┆ list[i64] │
╞═════╪══════╪══════╪═════╪═══╪═══════════╪═══════════╪═══════════╪═══════════╡
│ 1301   ┆ … ┆ [0, 1, 2] ┆ [1, 2]    ┆ []        ┆ [1]       │
│ 2201   ┆ … ┆ [0, 1]    ┆ []        ┆ []        ┆ []        │
│ 3101   ┆ … ┆ [0]       ┆ []        ┆ [1, 2]    ┆ []        │
└─────┴──────┴──────┴─────┴───┴───────────┴───────────┴───────────┴───────────┘

Log output

No response

Issue description

InvalidOperationError: range must be decreasing if 'step' is negative

if ranges 1->3 = [1, 2] and 3->1 = []
then with step=-1 should be: 1->3 = [] and 3->1 = [3, 2] and not error

PanicException: capacity overflow

going from 1/2/3 down to zero with step=-1 should work and not panic
1->0 = [1], 2->0 = [2, 1], 3->0 = [3, 2, 1]
going from 1/2/3 to 1 should work and not panic
1->1 = [], 2->1 = [], 3->1 = []

Expected behavior

All examples should work without exception or panic

Installed versions

Replace this line with the output of pl.show_versions(). Leave the backticks in place.
@Julian-J-S Julian-J-S added bug Something isn't working python Related to Python Polars labels Oct 20, 2023
@mcrumiller
Copy link
Contributor

Sorry, do you mean that we should return nulls in cases where the operation is invalid, and return value elsewhere?

@Julian-J-S
Copy link
Contributor Author

Julian-J-S commented Oct 23, 2023

Sorry, do you mean that we should return nulls in cases where the operation is invalid, and return value elsewhere?

no ;)

We discussed this here #11892 and we all agreed that <xxx>_ranges should behave like python/rust ranges like this:

  • no exceptions / no nulls (given that data types are correct)
  • for ascending ranges:
    • 3-6 = [3, 4, 5]
    • 6-3 = [] end is lower than start: no problem, there is no element in between so empty list
  • for descending ranges
    • 3-6 = [] end is higher than start: no problem, there is no element in between so empty list
    • 6-3 = [6, 5, 4]

@alexander-beedie
Copy link
Collaborator

alexander-beedie commented Nov 18, 2023

Closed/fixed by #12548 👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python Related to Python Polars
Projects
None yet
3 participants