Skip to content

fix(python): match Python range semantics for empty and descending ranges - #9781

Open
jackylee-ch wants to merge 2 commits into
vortex-data:developfrom
jackylee-ch:fix/python-range-semantics
Open

fix(python): match Python range semantics for empty and descending ranges#9781
jackylee-ch wants to merge 2 commits into
vortex-data:developfrom
jackylee-ch:fix/python-range-semantics

Conversation

@jackylee-ch

Copy link
Copy Markdown
Contributor

vx.array(range(3, 3)) raises SequenceArray length must be greater than zero, while
range(10, 3) and range(0, 10, -1) both return an empty array — test_from_range_invalid
already asserts those two. range_len reports coinciding bounds as Some(0) and only the
other two shapes as None, so the third empty shape reached Sequence, which holds at least
one element.

vx.array(range(5, 1, -1)) raises Step, -1, does not fit in requested dtype: u64: the
inference read the bounds but not the step. An explicitly requested unsigned dtype still
errors, which test_sequence_array_from_len asserts.

Tests

cargo test --release -p vortex-python --lib: 31 passed, 21 on develop. Restoring the old
empty-range branch fails the three bounds_coincide cases; dropping step > 0 from the
inference fails two more. Tests are Rust-side because test_from_range.py is open in #9546.

AI assistance

Written with agentic AI assistance; I checked each empty shape against range_len by hand.

…nges

`range_len` reports a range whose bounds coincide as `Some(0)`, which fell
through to `Sequence`, and that encoding requires at least one element. Route
every empty range to the primitive-array path instead.

Inferring the dtype from the bounds alone chose `U64` for a descending range,
so the negative step no longer fit. Move the inference next to `range_len` as
`range_ptype` and require a positive step for the unsigned choice.

Signed-off-by: jackylee-ch <qcsd2011@gmail.com>
@AdamGS

AdamGS commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Thank you @jackylee-ch! Do you mind adding a short python-side test here?

Comment thread vortex-python/src/arrays/range_to_sequence.rs
Both shapes raised before this branch, so `test_from_range.py` had no case for
either. Names follow the file's existing `<start>_<stop>_<step>` convention, and
the descending case compares against Python's own `range`, which is the
behaviour being matched.

Signed-off-by: jackylee-ch <qcsd2011@gmail.com>
@jackylee-ch

Copy link
Copy Markdown
Contributor Author

Added test_from_range_3_3 and test_from_range_5_1_minus_1 in ec72623. Both fail against the pre-fix source and pass with it — rebuilt in between with --reinstall-package vortex-data, since a cached wheel otherwise hides the difference. The rest of vortex-python/test is 337 passed.

Left your inline suggestion alone since you'd already resolved it.

@AdamGS AdamGS added the changelog/fix A bug fix label Sep 7, 2026
@codspeed-hq

codspeed-hq Bot commented Sep 7, 2026

Copy link
Copy Markdown

Merging this PR will regress 2 benchmarks

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 2 improved benchmarks
❌ 2 regressed benchmarks
✅ 2195 untouched benchmarks
⏩ 206 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation random_i16[0.95] 77.5 µs 95.8 µs -19.09%
WallTime mul_u32_nonnull_avx512 5.5 µs 6.2 µs -10.49%
WallTime arrow_checked_add_u32_neon[16384] 20.5 µs 12.8 µs +60.41%
Simulation random_i8[0.8] 99.2 µs 69.8 µs +42.12%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing jackylee-ch:fix/python-range-semantics (ec72623) with develop (dc1b355)

Open in CodSpeed

Footnotes

  1. 206 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@AdamGS AdamGS added the lang/python Relates to the Vortex Python API label Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/fix A bug fix lang/python Relates to the Vortex Python API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants