Convert numpy integer and float scalars to Python numbers on insert - #877
Open
TanbirRamim wants to merge 1 commit into
Open
TanbirRamim wants to merge 1 commit into
TanbirRamim wants to merge 1 commit into
Conversation
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.
Fixes #876.
Raw numpy scalars like
np.int64(5)were passed straight tosqlite3, which stores them via the buffer protocol as BLOBs (b'\x05\x00...'). The column types were already right, sinceCOLUMN_TYPE_MAPPINGknows the numpy types, but the values were not.jsonify_if_needed()now calls.item()onnp.integer/np.floatingvalues when numpy is installed.I left out other numpy types (
bool_,datetime64, ...) because they aren't in the type mapping yet and.item()isn't always what you'd want for them.Tests: added
test_insert_raw_numpy_scalars, which usespytest.importorskip("numpy"), so it runs in thenumpy: 1CI legs without needing pandas. It fails onmainand passes with the fix. The full suite passes with and without numpy installed. black, flake8, mypy, pyright andty checkare clean. This doesn't touch the test that #875 rewrites.📚 Documentation preview 📚: https://sqlite-utils--877.org.readthedocs.build/en/877/