Inf vs NaN
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.
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:
- Performance - in pyproj we will have to iterate over and change the values.
- 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?
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.
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 For sure! I don't have much experience with Cython, but so I can improve my knowledge.
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.
Based on the discussions in the PROJ thread, I am thinking waiting to see what happens there would be a good idea.
Alright, sounds good!