Repository navigation
Conversation
_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).
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
On the native package, a
SELECTof a record with a float array of 8 or more elements raisedModuleNotFoundError: No module named 'numpy'in an environment without the optionalnumpyextra. 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_takeinsrc/arcadedb/_native/lib.pyimported NumPy for it with no guard.lib.pynow has the same optional import ascodec.pyandcolumnar.py. With NumPy installed the reader is unchanged (np.frombufferon the same bytes). Without it the same bytes go into anarray.array("f"), which gives the same Python floats through the slices andtolist()thatcodec.loadsandloads_taggedask 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
_takeandcall_binname what the tail is.Checklist
tests/test_native_reply_reader.pyblock NumPy (thesys.modulesentry and the module's own handle). They read a built reply with and without floats, and run aSELECTand ato_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.uvx pre-commit run --files <changed files>passes, and so docompile,pyflakes(one older warning atlib.py:174, not from this change) andbanditon the two files