Skip to content

Fix zip_with_next raising TypeError when chained after lazy transforms - #219

Open
TrueFurina wants to merge 2 commits into
EntilZha:masterfrom
TrueFurina:fix/zip_with_next_precompute
Open

TrueFurina wants to merge 2 commits into
EntilZha:masterfrom
TrueFurina:fix/zip_with_next_precompute

Conversation

@TrueFurina

Copy link
Copy Markdown

Summary

Sequence.zip_with_next raises TypeError: 'map'/'filter' object is not subscriptable when it is chained after a lazy (non-PRE_COMPUTE) transform such as map, filter, select, etc.

Root cause

The transform is defined as:

def zip_with_next_t():
    return Transformation(
        "zip_with_next", lambda sequence: zip(sequence, sequence[1:]), None
    )

In the serial execution engine, a transform without PRE_COMPUTE receives the raw upstream iterator (not a list). Since zip_with_next subscripts its input (sequence[1:]), feeding it an iterator raises TypeError.

This is the same class of bug as #136 ("Reverse fails on sequences"), which was fixed for reverse by adding PRE_COMPUTE. The sibling transforms init, inits, tails, and sliding already use PRE_COMPUTE for exactly this reason — zip_with_next was simply missed when it was added in #217.

Fix

Mark zip_with_next_t with ExecutionStrategies.PRE_COMPUTE, matching its siblings. zip_with_next inherently needs the whole sequence (it pairs element i with i+1), so pre-computing is correct and does not change its semantics.

Verification

  • Added regression test test_zip_with_next_after_lazy_transform (serial + parallel).
  • Full suite: 311 passed, 3 skipped, 0 failures.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant