Fix optimizations that depend on python scalar being in idx_list.