Skip to content

Tests for NAs returned when X/Y coordinates are nan#290

Merged
paleolimbot merged 6 commits into
r-spatial:mainfrom
robitalec:patch-1
May 19, 2026
Merged

Tests for NAs returned when X/Y coordinates are nan#290
paleolimbot merged 6 commits into
r-spatial:mainfrom
robitalec:patch-1

Conversation

@robitalec

Copy link
Copy Markdown
Contributor

Details in #289

Adds tests for NAs returned when X and/or Y coordinates are nan.

Current behaviour:

library(s2)
p1 <- 'POINT (1 1)'
p2 <- 'POINT (2 nan)'
p3 <- 'POINT (nan nan)'

s2_distance_matrix(c(p1, p2, p3), c(p1, p2, p3))
#>          [,1]     [,2] [,3]
#> [1,]        0 20015118   NA
#> [2,] 20015118 20015118   NA
#> [3,]       NA       NA   NA

Expected behaviour:

library(s2)
p1 <- 'POINT (1 1)'
p2 <- 'POINT (2 nan)'
p3 <- 'POINT (nan nan)'

s2_distance_matrix(c(p1, p2, p3), c(p1, p2, p3))
#>          [,1]  [,2] [,3]
#> [1,]        0  NA   NA
#> [2,]       NA  NA   NA
#> [3,]       NA  NA   NA

@paleolimbot paleolimbot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@paleolimbot

Copy link
Copy Markdown
Collaborator

I also added the code to make the tests pass 🙂 . NaN coordinates are really undefined behaviour (except for the all empty case, which is canonically EMPTY), but here the failure mode is so bad that I think it's worth the extra check. For points we now treat them as EMPTY if they have any NaNs; when embedded in a sequence we now error.

@paleolimbot paleolimbot merged commit c97ca6c into r-spatial:main May 19, 2026
10 checks passed
@robitalec

Copy link
Copy Markdown
Contributor Author

Sounds good @paleolimbot - that seems like a great solution for a bit of a weird situation.
I'll close the original issue.
Thank you!

@robitalec robitalec deleted the patch-1 branch May 20, 2026 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants