Skip to content

Store NumPy booleans as SQLite integers - #975

Open
ShianMike wants to merge 1 commit into
simonw:mainfrom
ShianMike:fix/numpy-boolean-scalars
Open

ShianMike wants to merge 1 commit into
simonw:mainfrom
ShianMike:fix/numpy-boolean-scalars

Conversation

@ShianMike

@ShianMike ShianMike commented Nov 30, 2026 •

Copy link
Copy Markdown

Fixes #974.

NumPy boolean scalars now follow Python booleans for both column type inference and SQLite parameter binding. Inferred columns containing NumPy booleans, including when mixed with Python booleans, use INTEGER affinity. An explicit np.bool_ schema type also maps to INTEGER.

The regression cases cover newly inferred columns, mixed values, and explicit Python and NumPy boolean schema types. All four failed on main and pass with this change. A separate SQL check confirmed that WHERE enabled = 1 now matches the stored true value.

Verification

  • Python 3.14.0, SQLite 3.50.4, NumPy 2.5.5. uv run --no-sync pytest -q -rs returned 1,633 passed and 17 skips for platform or optional dependencies.
  • Python 3.11.14 without NumPy. pytest tests/test_create.py tests/test_utils.py -q returned 236 passed and 6 skips.
  • Black, Flake8, mypy, and Pyright passed.

📚 Documentation preview 📚: https://sqlite-utils--975.org.readthedocs.build/en/975/

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-30T08:28:27.191441Z 0cc1b0d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0cc1b0db99

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sqlite_utils/db.py
if isinstance(value, decimal.Decimal):
return float(value)
if np is not None and isinstance(value, (np.integer, np.floating)):
if np is not None and isinstance(value, (np.integer, np.floating, np.bool_)):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Normalize NumPy booleans in lookup predicates too

For a lookup table pre-created with an enabled column typed as bool, calling table.lookup({'enabled': np.bool_(True)}) twice now raises IntegrityError on the second call instead of returning the existing ID. This conversion stores integer 1, but Table.lookup() still forwards the original scalar to rows_where(), where SQLite binds it as a BLOB. The query therefore misses the row and attempts an insertion that violates the unique index. Previously both operations used the BLOB representation and the lookup succeeded. Normalize lookup predicate values with the same conversion to preserve idempotency.

Useful? React with 👍 / 👎.

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

Successfully merging this pull request may close these issues.

NumPy booleans are stored as BLOBs or raise during table inference

1 participant