Replace err with float('inf')