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

[BUG] generator expression returns wrong result when converted to cython code #5250

Closed
Chrisenvel opened this issue Feb 17, 2023 · 1 comment

Comments

@Chrisenvel
Copy link

Describe the bug

The provided code snippet behaves differently depending on if it is run in python or converted to cython code and run there. I was not able to figure out what exactly is causing the changed behaviour.

I am aware that the code can be simplified with zip, but would still be interested in knowing what exactly is causing this.

Code to reproduce the behaviour:

def example():
    column1 = [1, 2, 3]
    column2 = ['a', 'b', 'c']

    gen = [(cell for cell in col) for col in [column1, column2]]

    rows = []
    for _ in range(3):
        row = [next(col) for col in gen]
        rows.append(row)
    print(rows)

Expected behaviour

when run in python and cython, it should print [[1, 'a'], [2, 'b'], [3, 'c']]. Instead, it only prints the result in python, in cython it prints [['a', 'a'], ['b', 'b'], ['c', 'c']] instead.

Environment

OS: macOS
Python version 3.9.13
Cython version 0.29.28

Additional context

No response

@Chrisenvel Chrisenvel changed the title [BUG] expression returns wrong result when converted to cython code [BUG] generator expression returns wrong result when converted to cython code Feb 17, 2023
@scoder
Copy link
Contributor

scoder commented Feb 17, 2023

Duplicate of #1159.

@scoder scoder closed this as completed Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants