Dealing with Inf or -Inf pixels

Inf pixels are a pain, because the empty areas of a render could be inf as well. So sampling the z with an expression node and using the value of an adjacent pixel for each of them will mess up your edges. If possible, try sampling the surrounding area instead. This will leave the edges intact but deal with the odd erroneous pixel.