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.

MAINT: unify spatial index error handling

See original GitHub issue

Currently, there is no unified approach to error handling for empty spatial indexes or lack of a spatail index backend:

  • sjoin does it’s own check for rtree, this means you need rtree even if you have pygeos!
  • overlay and clip do not do any checks, they would fail with something like None does not have any attribute query_bulk, which is not very helpful.

Further, when you create a spatial index, if:

  • The spatial index is empty, GeoDataFrame.sindex gets set to None
  • There is not spatial index backend, GeoDataFrame.sindex gets set to None and a warning is raised.

I don’t particularly like that handling. There is no way to tell what happened, aside from a warning.

I would like to propose the following:

  • No modules outside of sindex shall check for a spatial index backend. They should just blindly try to access the sindex property.
  • The sindex backends should be instantiated even with no geometries, and should have a __len__ property that reports 0 when empty (this preserves the if gdf.sindex: syntax used in some modules).
  • In the case of no spatial index backend, a clear error should be raised by `sindex.*

* Currently, the error is raised only when a property of the spatial index is accessed (sindex.intersection). There are two options with this:

  1. Preserve the current behavior, but make the error more useful. This would require setting GeoDataFrame.sindex to some non-None value, perhaps a dummy class that raises a user friendly error if any of its methods (query, query_bulk, etc.) are accessed and always reports a len of 0. The big con of this approach is complexity. We’d have to make a dummy class, etc.
  2. Raise an error when GeoDataFrame.sindex is accessed. This is the lower complexity approach, we just replace what is currently a warning with an error. It would however require either a try/except block or an import of geopandas.sindex.has_sindex by other modules to handle this error if they want to operate without a spatial index. Currently, all modules that use a spatial index cannot operate without a spatial index, so they would actually not need to do anything.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
adriangbcommented, May 20, 2020

A deprecation warning seems fine to me. So:

  • No backend raises an error (currently a warning, which is followed by some downstream error).
  • Empty spatial index raises a deprecation warning and gets set to None, in the future will be set to a spatial index instance with len == 0.
0reactions
brendan-wardcommented, May 20, 2020

👍

In the case of no spatial index backend, a clear error should be raised by sindex.*

Conflating None as an indicator of an empty spatial index with a missing backend is not at all ideal here. Unmet dependencies should raise errors.

A deprecation period seems fine for this, in which case it would be good to get the deprecation warning into 0.8.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem: Unable to merge feature classes using the Merge tool
This error usually indicates that there are inconsistencies in the spatial index grid values of the feature classes to be merged.
Read more >
Error handling with sync—ArcGIS REST APIs
This topic discusses error cases when using the feature service's createReplica and synchronizeReplica operations. This includes errors and failures due to ...
Read more >
Are unfixable spatial index corruptions considered normal?
4427.24 (SQL Server 2014 SP1 CU3). I scripted the table with schema and data, fresh DB, execute. Same error. CHECKDB also has this...
Read more >
5 Indexing and Querying Spatial Data - Oracle Help Center
After you have loaded spatial data , you should create a spatial index on it to enable efficient query performance using the data....
Read more >
Optimize index maintenance to improve query performance ...
This article describes index maintenance concepts, and a recommended strategy to maintain indexes.
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