Ignore nan values when calculating path distance.