pyproj icon indicating copy to clipboard operation
pyproj copied to clipboard

Inf vs NaN

Open sfinkens opened this issue 5 years ago • 7 comments

Currently pyproj returns inf whenever a projection operation fails, which is coherent with the behaviour of PROJ. However, I could see some benefits from changing this to NaN, see https://github.com/OSGeo/PROJ/issues/2376.

Since the PROJ developers are cautious making such a breaking change, would it be an option to expose NaN instead of inf in pyproj? Downstream applications using np.isfinite to filter invalid values would not be affected, since this also filters NaN. It would be a breaking change for users checking lat > 90 for instance.

sfinkens avatar Oct 15 '20 07:10 sfinkens

I hope that they aren't opposed to the change forever, just something that could wait. Maybe it can be a PROJ 9+ change :). It would be much better to have this change in PROJ for at least two reasons I can think if:

  1. Performance - in pyproj we will have to iterate over and change the values.
  2. Clarity - was the value really a NaN or was it a valid value that is supposed to be an Inf? Only PROJ really knows.

Since they are all Inf, going to all NaN makes more sense to me as it means the data is invalid. And since any potentially valid and invalid data is mixed together it might as well all be invalid. However, due to performance and consistency reasons, I would prefer that this is something that is enabled optionally. My initial thinking was a global flag that could be set by pyproj.inf_to_nan(). Then, convert all output returned by PROJ to NaN consistently.

Thoughts?

snowman2 avatar Oct 15 '20 13:10 snowman2

Yes I hope so, too :) And I completely agree with your reasoning, that's why I asked the PROJ developers in the first place. Making this behaviour optional sounds like a good idea to me. I could also imagine something like pyproj.set_options(fill_value='nan/inf'), similar to xarray.

sfinkens avatar Oct 15 '20 13:10 sfinkens

pyproj.set_options(fill_value='nan/inf')

Sounds like a good idea to me. @sfinkens is this something you are interested in implementing/have bandwidth to implement in pyproj?

snowman2 avatar Oct 15 '20 13:10 snowman2

@snowman2 For sure! I don't have much experience with Cython, but so I can improve my knowledge.

sfinkens avatar Oct 15 '20 14:10 sfinkens

I don't have much experience with Cython, but so I can improve my knowledge.

That's where all cython developers start :zap: . If you have any questions, feel free to reach out.

snowman2 avatar Oct 15 '20 14:10 snowman2

Based on the discussions in the PROJ thread, I am thinking waiting to see what happens there would be a good idea.

snowman2 avatar Oct 21 '20 00:10 snowman2

Alright, sounds good!

sfinkens avatar Oct 21 '20 08:10 sfinkens