BasPH opened a new issue, #26499:
URL: https://github.com/apache/airflow/issues/26499

   ### Apache Airflow version
   
   2.4.0
   
   ### What happened
   
   When running `zip()` with different-length lists, I get an unexpected result:
   
   ```python
   from datetime import datetime
   
   from airflow import DAG
   from airflow.decorators import task
   
   with DAG(
       dag_id="demo_dynamic_task_mapping_zip",
       start_date=datetime(2022, 1, 1),
       schedule=None,
   ):
   
       @task
       def push_letters():
           return ["a", "b", "c"]
   
       @task
       def push_numbers():
           return [1, 2, 3, 4]
   
       @task
       def pull(value):
           print(value)
   
       pull.expand(value=push_letters().zip(push_numbers()))
   ```
   
   Iterates over `[("a", 1), ("b", 2), ("c", 3), ("a", 1)]`, so it iterates for 
the length of the longest collection, but restarts iterating elements when 
reaching the length of the shortest collection.
   
   I would expect it to behave like Python's builtin `zip` and iterates for the 
length of the shortest collection, so 3x in the example above, i.e. `[("a", 1), 
("b", 2), ("c", 3)]`.
   
   Additionally, I went digging in the source code and found the `fillvalue` 
argument which works as expected:
   
   ```python
   pull.expand(value=push_letters().zip(push_numbers(), fillvalue="foo"))
   ```
   
   Iterates over `[("a", 1), ("b", 2), ("c", 3), ("foo", 4)]`.
   
   However, with `fillvalue` not set, I would expect it to iterate only for the 
length of the shortest collection.
   
   ### What you think should happen instead
   
   I expect `zip()` to iterate over the number of elements of the shortest 
collection (without `fillvalue` set).
   
   ### How to reproduce
   
   See above.
   
   ### Operating System
   
   MacOS
   
   ### Versions of Apache Airflow Providers
   
   _No response_
   
   ### Deployment
   
   Other
   
   ### Deployment details
   
   OSS Airflow
   
   ### Anything else
   
   _No response_
   
   ### Are you willing to submit PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to