fastquadtree 1.3.0__cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl → 1.3.2__cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of fastquadtree might be problematic. Click here for more details.

@@ -29,6 +29,14 @@ G = TypeVar("G") # geometry type, e.g. Point or Bounds
29
29
  HitT = TypeVar("HitT") # raw native tuple, e.g. (id,x,y) or (id,x0,y0,x1,y1)
30
30
  ItemType = TypeVar("ItemType", bound=Item) # e.g. PointItem or RectItem
31
31
 
32
+ # Quadtree dtype to numpy dtype mapping
33
+ QUADTREE_DTYPE_TO_NP_DTYPE = {
34
+ "f32": "float32",
35
+ "f64": "float64",
36
+ "i32": "int32",
37
+ "i64": "int64",
38
+ }
39
+
32
40
 
33
41
  def _is_np_array(x: Any) -> bool:
34
42
  mod = getattr(x.__class__, "__module__", "")
@@ -250,7 +258,7 @@ class _BaseQuadTree(Generic[G, HitT, ItemType], ABC):
250
258
  ) -> int:
251
259
  """
252
260
  Bulk insert with auto-assigned contiguous ids. Faster than inserting one-by-one.<br>
253
- Can accept either a Python sequence of geometries or a NumPy array of shape (N,2) or (N,4) with dtype float32.
261
+ Can accept either a Python sequence of geometries or a NumPy array of shape (N,2) or (N,4) with a dtype that matches the quadtree's dtype.
254
262
 
255
263
  If tracking is enabled, the objects will be bulk stored internally.
256
264
  If no objects are provided, the items will have obj=None (if tracking).
@@ -289,8 +297,12 @@ class _BaseQuadTree(Generic[G, HitT, ItemType], ABC):
289
297
  if geoms.size == 0:
290
298
  return 0
291
299
 
292
- if geoms.dtype != _np.float32:
293
- raise TypeError("Numpy array must use dtype float32")
300
+ # Check if dtype matches quadtree dtype
301
+ expected_np_dtype = QUADTREE_DTYPE_TO_NP_DTYPE.get(self._dtype)
302
+ if geoms.dtype != expected_np_dtype:
303
+ raise TypeError(
304
+ f"Numpy array dtype {geoms.dtype} does not match quadtree dtype {self._dtype}"
305
+ )
294
306
 
295
307
  if self._store is None:
296
308
  # Simple contiguous path with native bulk insert
Binary file
@@ -161,7 +161,7 @@ class QuadTree(_BaseQuadTree[Point, _IdCoord, PointItem]):
161
161
  """Create the native engine instance."""
162
162
  rust_cls = DTYPE_MAP.get(self._dtype)
163
163
  if rust_cls is None:
164
- raise ValueError(f"Unsupported dtype: {self._dtype}")
164
+ raise TypeError(f"Unsupported dtype: {self._dtype}")
165
165
  return rust_cls(bounds, capacity, max_depth)
166
166
 
167
167
  @classmethod
@@ -169,7 +169,7 @@ class QuadTree(_BaseQuadTree[Point, _IdCoord, PointItem]):
169
169
  """Create a new native engine instance from serialized bytes."""
170
170
  rust_cls = DTYPE_MAP.get(dtype)
171
171
  if rust_cls is None:
172
- raise ValueError(f"Unsupported dtype: {dtype}")
172
+ raise TypeError(f"Unsupported dtype: {dtype}")
173
173
  return rust_cls.from_bytes(data)
174
174
 
175
175
  @staticmethod
fastquadtree/pyqtree.py CHANGED
@@ -5,8 +5,9 @@ drop-in replacement to fastquadtree.
5
5
 
6
6
  from __future__ import annotations
7
7
 
8
+ from collections.abc import Iterable
8
9
  from operator import itemgetter
9
- from typing import Any, Tuple
10
+ from typing import Any, SupportsFloat, Tuple
10
11
 
11
12
  from ._native import RectQuadTree
12
13
 
@@ -34,18 +35,18 @@ def gather_objs(objs, ids, chunk=2048):
34
35
 
35
36
  class Index:
36
37
  """
37
- The class below is taken from the pyqtree package, but the implementation
38
+ The interface of the class below is taken from the pyqtree package, but the implementation
38
39
  has been modified to use the fastquadtree package as a backend instead of
39
40
  the original pure-python implementation.
40
41
  Based on the benchmarks, this gives a overall performance boost of 6.514x.
41
42
  See the benchmark section of the docs for more details and the latest numbers.
42
43
 
43
- Original docstring from pyqtree follows:
44
- The top spatial index to be created by the user. Once created it can be
45
- populated with geographically placed members that can later be tested for
46
- intersection with a user inputted geographic bounding box. Note that the
47
- index can be iterated through in a for-statement, which loops through all
48
- all the quad instances and lets you access their properties.
44
+ Index is the top-level class for creating and using a quadtree spatial index
45
+ with the original pyqtree interface. If you are not migrating from pyqtree,
46
+ consider using the RectQuadTree class for detailed control and better performance.
47
+
48
+ This class wraps a RectQuadTree instance and provides methods to insert items with bounding boxes,
49
+ remove items, and query for items intersecting a given bounding box.
49
50
 
50
51
  Example usage:
51
52
  ```python
@@ -65,32 +66,36 @@ class Index:
65
66
 
66
67
  def __init__(
67
68
  self,
68
- bbox=None,
69
- x=None,
70
- y=None,
71
- width=None,
72
- height=None,
73
- max_items=MAX_ITEMS,
74
- max_depth=MAX_DEPTH,
69
+ bbox: Iterable[SupportsFloat] | None = None,
70
+ x: float | int | None = None,
71
+ y: float | int | None = None,
72
+ width: float | int | None = None,
73
+ height: float | int | None = None,
74
+ max_items: int = MAX_ITEMS,
75
+ max_depth: int = MAX_DEPTH,
75
76
  ):
76
77
  """
77
78
  Initiate by specifying either 1) a bbox to keep track of, or 2) with an xy centerpoint and a width and height.
78
79
 
79
- Parameters:
80
- - **bbox**: The coordinate system bounding box of the area that the quadtree should
80
+ Args:
81
+ bbox: The coordinate system bounding box of the area that the quadtree should
81
82
  keep track of, as a 4-length sequence (xmin,ymin,xmax,ymax)
82
- - **x**:
83
+ x:
83
84
  The x center coordinate of the area that the quadtree should keep track of.
84
- - **y**
85
+ y:
85
86
  The y center coordinate of the area that the quadtree should keep track of.
86
- - **width**:
87
+ width:
87
88
  How far from the xcenter that the quadtree should look when keeping track.
88
- - **height**:
89
+ height:
89
90
  How far from the ycenter that the quadtree should look when keeping track
90
- - **max_items** (optional): The maximum number of items allowed per quad before splitting
91
- up into four new subquads. Default is 10.
92
- - **max_depth** (optional): The maximum levels of nested subquads, after which no more splitting
91
+ max_items (optional): The maximum number of items allowed per quad before splitting
92
+ up into four new subquads. Default is 10.
93
+ max_depth (optional): The maximum levels of nested subquads, after which no more splitting
93
94
  occurs and the bottommost quad nodes may grow indefinately. Default is 20.
95
+
96
+ Note:
97
+ Either the bbox argument must be set, or the x, y, width, and height
98
+ arguments must be set.
94
99
  """
95
100
  if bbox is not None:
96
101
  x1, y1, x2, y2 = bbox
@@ -114,15 +119,15 @@ class Index:
114
119
  self._free = []
115
120
  self._item_to_id = {}
116
121
 
117
- def insert(self, item: Any, bbox): # pyright: ignore[reportIncompatibleMethodOverride]
122
+ def insert(self, item: Any, bbox: Iterable[SupportsFloat]):
118
123
  """
119
124
  Inserts an item into the quadtree along with its bounding box.
120
125
 
121
- Parameters:
122
- - **item**: The item to insert into the index, which will be returned by the intersection method
123
- - **bbox**: The spatial bounding box tuple of the item, with four members (xmin,ymin,xmax,ymax)
126
+ Args:
127
+ item: The item to insert into the index, which will be returned by the intersection method
128
+ bbox: The spatial bounding box tuple of the item, with four members (xmin,ymin,xmax,ymax)
124
129
  """
125
- if type(bbox) is list: # Handle list input
130
+ if type(bbox) is not tuple: # Handle non-tuple input
126
131
  bbox = tuple(bbox)
127
132
 
128
133
  if self._free:
@@ -134,17 +139,18 @@ class Index:
134
139
  self._qt.insert(rid, bbox)
135
140
  self._item_to_id[id(item)] = rid
136
141
 
137
- def remove(self, item, bbox):
142
+ def remove(self, item: Any, bbox: Iterable[SupportsFloat]):
138
143
  """
139
144
  Removes an item from the quadtree.
140
145
 
141
- Parameters:
142
- - **item**: The item to remove from the index
143
- - **bbox**: The spatial bounding box tuple of the item, with four members (xmin,ymin,xmax,ymax)
146
+ Args:
147
+ item: The item to remove from the index
148
+ bbox: The spatial bounding box tuple of the item, with four members (xmin,ymin,xmax,ymax)
144
149
 
145
- Both parameters need to exactly match the parameters provided to the insert method.
150
+ Note:
151
+ Both parameters need to exactly match the parameters provided to the insert method.
146
152
  """
147
- if type(bbox) is list: # Handle list input
153
+ if type(bbox) is not tuple: # Handle non-tuple input
148
154
  bbox = tuple(bbox)
149
155
 
150
156
  rid = self._item_to_id.pop(id(item))
@@ -152,18 +158,18 @@ class Index:
152
158
  self._objects[rid] = None
153
159
  self._free.append(rid)
154
160
 
155
- def intersect(self, bbox):
161
+ def intersect(self, bbox: Iterable[SupportsFloat]) -> list:
156
162
  """
157
- Intersects an input boundingbox rectangle with all of the items
163
+ Intersects an input bounding box rectangle with all of the items
158
164
  contained in the quadtree.
159
165
 
160
- Parameters:
161
- - **bbox**: A spatial bounding box tuple with four members (xmin,ymin,xmax,ymax)
166
+ Args:
167
+ bbox: A spatial bounding box tuple with four members (xmin,ymin,xmax,ymax)
162
168
 
163
169
  Returns:
164
- - A list of inserted items whose bounding boxes intersect with the input bbox.
170
+ A list of inserted items whose bounding boxes intersect with the input bbox.
165
171
  """
166
- if type(bbox) is list: # Handle list input
172
+ if type(bbox) is not tuple: # Handle non-tuple input
167
173
  bbox = tuple(bbox)
168
174
  result = self._qt.query_ids(bbox)
169
175
  # result = [id1, id2, ...]
@@ -101,7 +101,7 @@ class RectQuadTree(_BaseQuadTree[Bounds, _IdRect, RectItem]):
101
101
  """Create the native engine instance."""
102
102
  rust_cls = DTYPE_MAP.get(self._dtype)
103
103
  if rust_cls is None:
104
- raise ValueError(f"Unsupported dtype: {self._dtype}")
104
+ raise TypeError(f"Unsupported dtype: {self._dtype}")
105
105
  return rust_cls(bounds, capacity, max_depth)
106
106
 
107
107
  @classmethod
@@ -109,7 +109,7 @@ class RectQuadTree(_BaseQuadTree[Bounds, _IdRect, RectItem]):
109
109
  """Create a new native engine instance from serialized bytes."""
110
110
  rust_cls = DTYPE_MAP.get(dtype)
111
111
  if rust_cls is None:
112
- raise ValueError(f"Unsupported dtype: {dtype}")
112
+ raise TypeError(f"Unsupported dtype: {dtype}")
113
113
  return rust_cls.from_bytes(data)
114
114
 
115
115
  @staticmethod
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastquadtree
3
- Version: 1.3.0
3
+ Version: 1.3.2
4
4
  Classifier: Programming Language :: Python :: 3
5
5
  Classifier: Programming Language :: Python :: 3 :: Only
6
6
  Classifier: Programming Language :: Rust
@@ -0,0 +1,13 @@
1
+ fastquadtree-1.3.2.dist-info/METADATA,sha256=bAU2hORz6fiyCP29h2k3maX1pxggD4XTXEZpYcw28G8,9747
2
+ fastquadtree-1.3.2.dist-info/WHEEL,sha256=cqfH6P_NujaeOc1olR46J5a7YgoxWJnrr5iZ1_DMqps,129
3
+ fastquadtree-1.3.2.dist-info/licenses/LICENSE,sha256=pRuvcuqIMtEUBMgvP1Bc4fOHydzeuA61c6DQoQ1pb1w,1071
4
+ fastquadtree/__init__.py,sha256=rtkveNz7rScRasTRGu1yEqzeoJfLfreJNxg21orPL-U,195
5
+ fastquadtree/_base_quadtree.py,sha256=8YXQ9txNHlOD0wFv78PU17JumL4Nb_WnZIwt1FOgMy8,16325
6
+ fastquadtree/_item.py,sha256=EDS3nJHdVtjDsuTqTZKGTZH8iWJIQ-TKxLXqvMScNPA,2405
7
+ fastquadtree/_native.abi3.so,sha256=b3Bxj9RA-1TIpBR3JTZAMCc-epv8rcV-DaH0rcA-yqA,729512
8
+ fastquadtree/_obj_store.py,sha256=HeYFGUPYhvxBzL7Js0g0jsIxflpZS6RsXNk50rGeNlA,6522
9
+ fastquadtree/point_quadtree.py,sha256=BbTlY1hJLh5oVI7zgkjMCReO8GlPKy4pJqHHSZKo5SA,6179
10
+ fastquadtree/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ fastquadtree/pyqtree.py,sha256=3_L_ggKmtqXZNXSCYUDKh4uVMe-k78SgBNSYCJv3Cpw,6434
12
+ fastquadtree/rect_quadtree.py,sha256=zD3MqFqDJRd3oJcuT5EMkuMnq_ABfMVhf-wXbidK7jE,4002
13
+ fastquadtree-1.3.2.dist-info/RECORD,,
@@ -1,13 +0,0 @@
1
- fastquadtree-1.3.0.dist-info/METADATA,sha256=NIDXaSGreQNVvoCiTLKAty1ylz_-PsnQe_ABTWrQ6u4,9747
2
- fastquadtree-1.3.0.dist-info/WHEEL,sha256=cqfH6P_NujaeOc1olR46J5a7YgoxWJnrr5iZ1_DMqps,129
3
- fastquadtree-1.3.0.dist-info/licenses/LICENSE,sha256=pRuvcuqIMtEUBMgvP1Bc4fOHydzeuA61c6DQoQ1pb1w,1071
4
- fastquadtree/__init__.py,sha256=rtkveNz7rScRasTRGu1yEqzeoJfLfreJNxg21orPL-U,195
5
- fastquadtree/_base_quadtree.py,sha256=BTOvu1FM9oBzEMh2JTzfeJiPrrjtmWKU1JJS1DfR7UE,15925
6
- fastquadtree/_item.py,sha256=EDS3nJHdVtjDsuTqTZKGTZH8iWJIQ-TKxLXqvMScNPA,2405
7
- fastquadtree/_native.abi3.so,sha256=oGDIRMYxQJFk9Uu-6z4MlsWrrdSSQZJwFqUD1ESbOH0,729512
8
- fastquadtree/_obj_store.py,sha256=HeYFGUPYhvxBzL7Js0g0jsIxflpZS6RsXNk50rGeNlA,6522
9
- fastquadtree/point_quadtree.py,sha256=zpvd9EJUcT2soMP89yQJgpaht9-vz7DG5tDqaad8GEc,6181
10
- fastquadtree/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
- fastquadtree/pyqtree.py,sha256=2Khh1gCPalD4z0gb3EmqtzMoga08E9BkB0j5bwkiRPU,6076
12
- fastquadtree/rect_quadtree.py,sha256=uVzaRTs-ZEcD1PGlQjfnLP6HWnOkr2zp6elO7sMDwow,4004
13
- fastquadtree-1.3.0.dist-info/RECORD,,