question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Calculating distances with np.nan gives incorrect result

See original GitHub issue

Running the following code:

from shapely.geometry import Point
import numpy as np

a = Point(1, 1)
b = Point(np.nan, np.nan)

a.distance(b)
a.hausdorff_distance(b)

will output np.nan for the hausdorff_distance which I believe is correct but the distance function outputs a huge number. Shouldn’t it output np.nan?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jorisvandenbosschecommented, Feb 16, 2022
0reactions
jorisvandenbosschecommented, Aug 22, 2022

All the example cases from above, both with empty Point or empty GeometryCollection, and both with distance and hausdorff_distance, now return NaN with the latest GEOS version on the main branch.

So I think this can be closed?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issue in handling NaN for distance calculation? - Stack Overflow
I wanted to calculate distance between two NaN which should result as 0 and distance between NaN to any number or any string...
Read more >
Don't Fall Into the NaN Trap - Level Up Coding
Floating point calculation NaN (not a number) results can cause ... this whole test is bogus because the property name distance is wrong....
Read more >
Pdist gives NAN but there are no missing values in input array
I am using the pdist function to calculate pairwise distances (jaccard) between two observations. Now what happens sometimes, seemingly at ...
Read more >
How to count the number of NaN values in Pandas?
We can use the describe() method which returns a table containing details about the dataset. The count property directly gives the count of...
Read more >
Cosine similarity with arrays contaning NaN
I am trying to calculate a cosine similarity using Python in order to find similar users basing on ratings they have given to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found