Skip to content

fix(#444): the native reply reader reads the float32 tail without NumPy - #470

Open
tae898 wants to merge 2 commits into
mainfrom
fix/444-native-float-tail-without-numpy
Open

tae898 wants to merge 2 commits into
mainfrom
fix/444-native-float-tail-without-numpy

Conversation

@tae898

@tae898 tae898 commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

On the native package, a SELECT of a record with a float array of 8 or more elements raised ModuleNotFoundError: No module named 'numpy' in an environment without the optional numpy extra. The cause is the one I read in #444: the library hands such an array back in a float32 tail after the JSON text, and _take in src/arcadedb/_native/lib.py imported NumPy for it with no guard.

lib.py now has the same optional import as codec.py and columnar.py. With NumPy installed the reader is unchanged (np.frombuffer on the same bytes). Without it the same bytes go into an array.array("f"), which gives the same Python floats through the slices and tolist() that codec.loads and loads_tagged ask of it.

Related issues

Closes #444. It is a bug in a plain install and the change is small, so I moved it from 27.1.1 to 26.12.1, as the milestone says it keeps the bugs.

Performance changes

None claimed. With NumPy installed the call is the one that was there, and the check of a module-level name replaces the import statement that ran on each reply with a tail.

Docs

No page describes it. The docstrings of _take and call_bin name what the tail is.

Checklist

  • A regression test fails on the old code and passes on the new: two tests in tests/test_native_reply_reader.py block NumPy (the sys.modules entry and the module's own handle). They read a built reply with and without floats, and run a SELECT and a to_json_list() of a 16-float property through a database. On the old code the import raises. I wrote them first and have not run them: the queue guard of my laptop blocks the test runner, so the run of this pull request is their first. I will not call this verified before that run is green.
  • The test suite that the change can affect passes (the native parity run of this pull request: the reply reader tests and the vector and result tests)
  • uvx pre-commit run --files <changed files> passes, and so do compile, pyflakes (one older warning at lib.py:174, not from this change) and bandit on the two files

_take imported numpy unguarded when a reply carried a float32 tail, so a SELECT of a record with a float array of 8 or more elements raised ModuleNotFoundError in an environment without the optional numpy extra. With NumPy installed nothing changes (np.frombuffer, as before); without it the same bytes are read into array.array('f'), which gives the same Python floats through the slices and tolist() that codec.loads asks of it.

Two regression tests in test_native_reply_reader.py block NumPy (sys.modules entry set to None, and the module's own handle): the reader on a built reply with and without floats, and a SELECT and to_json_list of a 16-float property through a database. They were written first and not run locally: the queue guard of this laptop blocks pytest while the Tower is down, so CI is their first run (compile, pyflakes, pre-commit and bandit were run).
@tae898 tae898 added this to the 26.12.1 milestone Nov 24, 2026
@tae898 tae898 added bug Something isn't working native The arcadedb package (native library build) python Pull requests that update python code labels Nov 24, 2026
@tae898 tae898 self-assigned this Nov 24, 2026
The parity run of the first push (run 45391421407, linux-x86_64, Python 3.12) failed test_a_select_of_a_float_array_needs_no_numpy at its setup: the native build has auto-transaction off, so INSERT INTO FloatDoc raised 'Transaction not begun' before NumPy was blocked. The other new test (the reader on a built reply, with and without floats) passed there. The INSERT now sits in db.transaction(), as in test_native_json_list.py. The read without NumPy that this test is about has not run yet; compile, pyflakes, pre-commit and bandit were run on the file.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working native The arcadedb package (native library build) python Pull requests that update python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native package without NumPy: SELECT of a record with a float array raises ModuleNotFoundError

1 participant