question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Loop.range generates inconsistent number of iterations when start=end

See original GitHub issue

/kind bug

What steps did you take and what happened:

Reproduce using the following code

from kfp import dsl, components
from kfp_tekton.tekton import Loop

op1_yaml = '''\
name: 'my-in-coop1'
inputs:
- {name: item, type: Integer}
- {name: param, type: Integer}
implementation:
    container:
        image: library/bash:4.4.23
        command: ['sh', '-c']
        args:
        - |
          set -e
          echo op1 "$0" "$1"
        - {inputValue: item}
        - {inputValue: param}
'''


@dsl.pipeline(name='pipeline')
def pipeline():
    with Loop.range(start=0, step=1, end=0) as item:
        op1_template = components.load_component_from_text(op1_yaml)
        op1 = op1_template(item, 10)

if __name__ == '__main__':
  from kfp_tekton.compiler import TektonCompiler as Compiler
  from kfp_tekton.compiler.pipeline_utils import TektonPipelineConf
  tekton_pipeline_conf = TektonPipelineConf()
  tekton_pipeline_conf.set_tekton_inline_spec(True)
  # tekton_pipeline_conf.set_resource_in_separate_yaml(True)
  Compiler().compile(pipeline, __file__.replace('.py', '.yaml'), tekton_pipeline_conf=tekton_pipeline_conf)

This generates 0 iterations.

What did you expect to happen: I expect this to generate 1 iteration given that the loop Loop.range(start=0, step=1, end=1) generates 2 iterations.

Additional information: [Miscellaneous information that will assist in solving the issue.]

Environment:

  • Python Version (use python --version):
  • SDK Version:
  • Tekton Version (use tkn version):
  • Kubernetes Version (use kubectl version):
  • OS (e.g. from /etc/os-release):

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
Tomclicommented, May 10, 2022

/assign @ScrapCodes

@ScrapCodes are you able to take over this issue?

0reactions
ScrapCodescommented, May 16, 2022

I think what DataStage wants is not the exact behavior of Python range. It’s similar to the requirement of enumerate where the index is counted from 1 instead of 0.

@Udiknedormin start = 0 end = 0, and step = n should be always one iteration in this case right?

Is it true of any start e.g. start = 1 and end =1 , should also generate one iteration.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does range(start, end) not include end? - Stack Overflow
The idea is that you get a list of length y-x , which you can (as you see above) iterate over. Read up...
Read more >
Loops and iteration - JavaScript - MDN Web Docs
It checks that i is less than the number of options in the <select> element, performs the succeeding if statement, and increments i...
Read more >
For loop with range - Learn Python 3 - Snakify
Another use case for a for-loop is to iterate some integer variable in increasing ... Function range(min_value, max_value) generates a sequence with numbers...
Read more >
Python range() Function Explained with Examples - PYnative
Python range() returns the sequence of numbers starting from a given start integer to a stop integer, which we can iterate using a...
Read more >
For Loop Over a Range - Activities - UiPath Community Forum
I am requesting that a new activity be added that can take a counter variable, start and end numbers, as well as a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found