Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Python 3.12.0rc1 #277

Closed
mwtoews opened this issue Aug 20, 2023 · 5 comments
Closed

Issue with Python 3.12.0rc1 #277

mwtoews opened this issue Aug 20, 2023 · 5 comments

Comments

@mwtoews
Copy link
Member

mwtoews commented Aug 20, 2023

There is a potential issue with Python 3.12.0rc1 shown here:

  platform linux -- Python 3.12.0rc1, pytest-7.4.0, pluggy-1.2.0
  cachedir: .tox/py312/.pytest_cache
  rootdir: /project
  collected 38 items
  tests/test_index.py ........x............F...............                [ 97%]
  tests/test_tpr.py .                                                      [100%]
  =================================== FAILURES ===================================
  _____________________ IndexSerialization.test_interleaving _____________________
  self = <tests.test_index.IndexSerialization testMethod=test_interleaving>
      def test_interleaving(self) -> None:
          """Streaming against a persisted index without interleaving"""
      
          def data_gen(
              interleaved: bool = True,
          ) -> Iterator[Tuple[int, Tuple[float, float, float, float], int]]:
              for i, (minx, miny, maxx, maxy) in enumerate(self.boxes15):
                  if interleaved:
                      yield (i, (minx, miny, maxx, maxy), 42)
                  else:
                      yield (i, (minx, maxx, miny, maxy), 42)
      
          p = index.Property()
          tname = tempfile.mktemp()
          idx = index.Index(
              tname, data_gen(interleaved=False), properties=p, interleaved=False
          )
          hits1 = sorted(list(idx.intersection((0, 60, 0, 60))))
          self.assertTrue(len(hits1), 10)
          self.assertEqual(hits1, [0, 4, 16, 27, 35, 40, 47, 50, 76, 80])
      
  >       leaves = idx.leaves()
  /project/tests/test_index.py:475: 
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
  self = rtree.index.Index(bounds=[-186.673789279, 184.761387556, -96.7177218184, 96.6043699778], size=100)
      def leaves(self):
          leaf_node_count = ctypes.c_uint32()
          p_leafsizes = ctypes.pointer(ctypes.c_uint32())
          p_leafids = ctypes.pointer(ctypes.c_int64())
          pp_childids = ctypes.pointer(ctypes.pointer(ctypes.c_int64()))
      
          pp_mins = ctypes.pointer(ctypes.pointer(ctypes.c_double()))
          pp_maxs = ctypes.pointer(ctypes.pointer(ctypes.c_double()))
          dimension = ctypes.c_uint32(0)
      
          core.rt.Index_GetLeaves(
              self.handle,
              ctypes.byref(leaf_node_count),
              ctypes.byref(p_leafsizes),
              ctypes.byref(p_leafids),
              ctypes.byref(pp_childids),
              ctypes.byref(pp_mins),
              ctypes.byref(pp_maxs),
              ctypes.byref(dimension),
          )
      
          output = []
      
          count = leaf_node_count.value
          sizes = ctypes.cast(p_leafsizes, ctypes.POINTER(ctypes.c_uint32 * count))
          ids = ctypes.cast(p_leafids, ctypes.POINTER(ctypes.c_int64 * count))
          child = ctypes.cast(
              pp_childids, ctypes.POINTER(ctypes.POINTER(ctypes.c_int64) * count)
          )
          mins = ctypes.cast(
              pp_mins, ctypes.POINTER(ctypes.POINTER(ctypes.c_double) * count)
          )
          maxs = ctypes.cast(
              pp_maxs, ctypes.POINTER(ctypes.POINTER(ctypes.c_double) * count)
          )
          for i in range(count):
              p_child_ids = child.contents[i]
      
              id = ids.contents[i]
              size = sizes.contents[i]
              child_ids_array = ctypes.cast(
                  p_child_ids, ctypes.POINTER(ctypes.c_int64 * size)
              )
      
              child_ids = []
              for j in range(size):
  >               child_ids.append(child_ids_array.contents[j])
  E               ValueError: NULL pointer access
  /project/rtree/index.py:1311: ValueError
  =============================== warnings summary ===============================
  tests/test_index.py::IndexSerialization::test_interleaving
    /project/rtree/index.py:283: DeprecationWarning: index.get_size() is deprecated, use len(index) instead
      warnings.warn(
  -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
  =========================== short test summary info ============================
  FAILED tests/test_index.py::IndexSerialization::test_interleaving - ValueErro...
  ============== 1 failed, 36 passed, 1 xfailed, 1 warning in 0.62s ==============

It's possible this is a Python issue rather than with rtree. It would be nice to resolve before Python 3.12.0 is finalized.

@musicinmybrain
Copy link
Contributor

From the Fedora package (for which I which I just took over as primary maintainer), it looks like this worked fine up through 3.12.0b4, and was probably broken by a change in 3.12.0rc1.

@musicinmybrain
Copy link
Contributor

The code here does look superficially similar to the reproducer in python/cpython#107940.

@mwtoews
Copy link
Member Author

mwtoews commented Aug 24, 2023

Thanks for the xrefs @musicinmybrain it seems well reported upstream, hopefully it will be resolved by rc2.

@musicinmybrain
Copy link
Contributor

I confirm this is fixed by Python 3.12.0rc2.

@mwtoews
Copy link
Member Author

mwtoews commented Sep 11, 2023

Thanks for checking @musicinmybrain !

@mwtoews mwtoews closed this as completed Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants