From 966df3a4b3ba158bb9780e964c064574d1525b05 Mon Sep 17 00:00:00 2001 From: Sandeep Murthy Date: Tue, 31 Dec 2019 18:42:24 +0000 Subject: [PATCH 1/3] Update `rtree.index.Index` - add index size method and update `__repr__` to display index bounds and index size --- rtree/index.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rtree/index.py b/rtree/index.py index c21667cb..1c8b2050 100644 --- a/rtree/index.py +++ b/rtree/index.py @@ -284,6 +284,12 @@ def __init__(self, *args, **kwargs): for item in stream: self.insert(*item) + def size(self): + return self.count(self.bounds) + + def __repr__(self): + return f'rtree.index.Index(bounds={self.bounds}, size={self.size()})' + def __getstate__(self): state = self.__dict__.copy() del state["handle"] From ba5a2470ee134dcf7c98d3e68f17ebc915db3279 Mon Sep 17 00:00:00 2001 From: Sandeep Murthy Date: Wed, 1 Jan 2020 02:25:28 +0000 Subject: [PATCH 2/3] Tweak `get_size` methods in `Index` and `RtreeContainer` classes + update docstrings --- rtree/index.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/rtree/index.py b/rtree/index.py index 1c8b2050..3e164a7f 100644 --- a/rtree/index.py +++ b/rtree/index.py @@ -147,7 +147,7 @@ def __init__(self, *args, **kwargs): >>> idx = index.Index(properties=p) >>> idx # doctest: +ELLIPSIS - + rtree.index.Index(bounds=[1.7976931348623157e+308, 1.7976931348623157e+308, -1.7976931348623157e+308, -1.7976931348623157e+308], size=0) Insert an item into the index:: @@ -284,11 +284,14 @@ def __init__(self, *args, **kwargs): for item in stream: self.insert(*item) - def size(self): - return self.count(self.bounds) + def get_size(self): + try: + return self.count(self.bounds) + except core.RTreeError: + return 0 def __repr__(self): - return f'rtree.index.Index(bounds={self.bounds}, size={self.size()})' + return f'rtree.index.Index(bounds={self.bounds}, size={self.get_size()})' def __getstate__(self): state = self.__dict__.copy() @@ -1827,7 +1830,7 @@ def __init__(self, *args, **kwargs): >>> idx = index.RtreeContainer(properties=p) >>> idx # doctest: +ELLIPSIS - + rtree.index.RtreeContainer(bounds=[1.7976931348623157e+308, 1.7976931348623157e+308, -1.7976931348623157e+308, -1.7976931348623157e+308], size=0) Insert an item into the index:: @@ -1853,6 +1856,15 @@ def __init__(self, *args, **kwargs): self._objects = {} return super(RtreeContainer, self).__init__(*args, **kwargs) + def get_size(self): + try: + return self.count(self.bounds) + except core.RTreeError: + return 0 + + def __repr__(self): + return f'rtree.index.RtreeContainer(bounds={self.bounds}, size={self.get_size()})' + def __contains__(self, obj): return id(obj) in self._objects From 931d2e538721db6a48fa0cdded343938a462469c Mon Sep 17 00:00:00 2001 From: Sandeep Murthy Date: Wed, 1 Jan 2020 10:25:46 +0000 Subject: [PATCH 3/3] Remove f-strings in index `__repr__` methods --- rtree/index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rtree/index.py b/rtree/index.py index 3e164a7f..69af61b8 100644 --- a/rtree/index.py +++ b/rtree/index.py @@ -291,7 +291,7 @@ def get_size(self): return 0 def __repr__(self): - return f'rtree.index.Index(bounds={self.bounds}, size={self.get_size()})' + return 'rtree.index.Index(bounds={}, size={})'.format(self.bounds, self.get_size()) def __getstate__(self): state = self.__dict__.copy() @@ -1863,7 +1863,7 @@ def get_size(self): return 0 def __repr__(self): - return f'rtree.index.RtreeContainer(bounds={self.bounds}, size={self.get_size()})' + return 'rtree.index.RtreeContainer(bounds={}, size={})'.format(self.bounds, self.get_size()) def __contains__(self, obj): return id(obj) in self._objects