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.

Distance from empty collection is zero

See original GitHub issue

Expected behavior and actual behavior.

Expected behaviour:

The distance from an empty collection should be +inf.

Actual behaviour:

The distance from an empty collection returns zero.

Steps to reproduce the problem.

Run the following script:

from shapely.geometry import Point, LineString

empty_thing = LineString()
assert empty_thing.is_empty
print(empty_thing.distance(Point(1, 1)))  # Returns zero, should probably be +inf

Operating system

Windows 10 64 bit

Shapely version and provenance

Python 3.6 Shapely 1.6b4 installed from PyPI using pip

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
mwtoewscommented, Jul 3, 2017

Similar to GEOS, JTS returns 0.0, so perhaps this behavior was drafted a long time ago.

PostGIS returns null for this scenario, since there are not any geometries to measure between. I’d suggest Shapely similarly return None if any of the inputs are empty.

1reaction
bixb0012commented, Jul 13, 2017

SQL Server spatial types return NULL, similar to PostGIS. Esri’s ArcPy generates an error. It seems we have 0, NULL, or error depending on whom you ask. I can see some merit behind arguments for any of them, so clear documentation is probably the most important part of addressing this issue. After all, without a consensus among geospatial products, it is a matter of expectations and not correctness.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Distance from empty collection is zero · Issue #498 - GitHub
Actual behaviour: The distance from an empty collection returns zero. Steps to reproduce the problem. Run the following script: from shapely.
Read more >
If distance between the two sets is zero then their intersection ...
For example R+ and R− have distance 0, but there is no real number that is both positive and negative (but a limit...
Read more >
On the indicators for perceiving empty sets as zero
The question whether human beings process empty sets as zero has received little research attention. In this study, we used the distance and...
Read more >
How Far Can You Go on 0 Miles to Empty? - Car Roar
You can go about 25 – 50 miles (40 – 80 km) when the car says 0 miles. If your car is heavy...
Read more >
What is the distance between any non-empty set and ... - Quora
which defines a distance between any two elements of the set. The metric has to have certain properties. If the set has zero...
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