rtree icon indicating copy to clipboard operation
rtree copied to clipboard

Allow string ids in indexes (or at least improve the error messages)

Open codeananda opened this issue 1 year ago • 2 comments

I've just spent the last couple of hours being super confused by the following error message.

from rtree import index

points = (0.0, 0.0, 1.0, 1.0)
def gen():
    for s, p in [('a', points)]:
        yield s, p
        
index.Index(gen())
RTreeError: Error in "Index_CreateWithStream": IllegalArgumentException: RTree::BulkLoader::bulkLoadUsingSTR: Empty data stream given.

Improvement requests:

  • Add the ability to use string indexes (useful for databases that use things like 00be976b-691b-4e1a-bcef-9336f13fb290 as keys), or
  • Improve the error message so that it tells you you shouldn't be using string indexes.

Similarly, this error could also be improved:

idx = index.Index()
idx.insert('a', points)
ArgumentError: argument 2: <class 'TypeError'>: wrong type

Issues:

  • Should be TypeError
  • It's the first argument

Something like

TypeError(f"Id values must be integers. Received {id=} with type {type(id}}")

I'm open to implementing some of the things but I don't know C, only Python.

codeananda avatar Jan 24 '24 12:01 codeananda

Add the ability to use string indexes (useful for databases that use things like 00be976b-691b-4e1a-bcef-9336f13fb290 as keys), or

This would require changing the design of libspatialindex. 👎

Improve the error message so that it tells you you shouldn't be using string indexes.

We would happily merge a PR that implemented a better error message and a test that demonstrated it.

hobu avatar Jan 29 '24 20:01 hobu

This would require changing the design of libspatialindex. 👎

I thought it might

We would happily merge a PR that implemented a better error message and a test that demonstrated it.

Cool

codeananda avatar Jan 30 '24 10:01 codeananda