You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/09/21 06:14:13 UTC

[GitHub] [airflow] rjmcginness commented on issue #26499: Dynamic task mapping zip() iterates unexpected number of times

rjmcginness commented on issue #26499:
URL: https://github.com/apache/airflow/issues/26499#issuecomment-1253252069

   Hello,  I am new here, but I have been wanting to contribute to this project.  I do not want to create a random pull request, so I am showing my changes here.  I did run the pre-commit and unit test shown above.  I was not able to run the DAG above in Docker, however on macOS.  My thought on this is that there may be different instances of NOTSET and, therefore, comparison is not working.  It compares against the object, rather than a value.  In order to solve this, perhaps testing against the class ArgNotSet would be more reliable.  I would create a PR, but I would like to test against the failed use case and do not want to violate the contribution decorum.
   
   ```
   class _ZipResult(Sequence):
       def __init__(self, values: Sequence[Sequence | dict], *, fillvalue: Any = NOTSET) -> None:
           self.values = values
           self.fillvalue = fillvalue
           # use the generator here, rather than in __len__ to improve efficiency
           lengths = (len(v) for v in self.values)
           self.length = min(lengths) if isinstance(self.fillvalue, ArgNotSet) else max(lengths)
   
       @staticmethod
       def _get_or_fill(container: Sequence | dict, index: Any, fillvalue: Any) -> Any:
           try:
               return container[index]
           except (IndexError, KeyError):
               return fillvalue
   
       def __getitem__(self, index: Any) -> Any:
           if index >= len(self):
               raise IndexError(index)
           return tuple(self._get_or_fill(value, index, self.fillvalue) for value in self.values)
   
       def __len__(self) -> int:
           return self.length
   ```


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org