[lesson 9]Help understanding combine_scheds

In Lesson 9, annealers section, there is this function combine_scheds as defined below:

def combine_scheds(pcts, scheds):
    assert sum(pcts) == 1.
    pcts = tensor([0] + listify(pcts))
    assert torch.all(pcts >= 0)
    pcts = torch.cumsum(pcts, 0)
    def _inner(pos):
        idx = (pos >= pcts).nonzero().max()
        if idx == 2: idx = 1
        actual_pos = (pos-pcts[idx]) / (pcts[idx+1]-pcts[idx])
        return scheds[idx](actual_pos)
    return _inner

Can someone please explain the following part of this code?

idx = (pos >= pcts).nonzero().max()
if idx == 2: idx = 1

I cant understand the purpose of these 2 lines… can someone please help me out?
Thanks in advance