Repository navigation
Decode JSON shared data values in query_df and query_np - #1177
Merged
joe-clickhouse merged 3 commits intoNov 11, 2026
Merged
joe-clickhouse merged 3 commits into
joe-clickhouse merged 3 commits into
Conversation
mansur-akhmadi
force-pushed
the
fix/query-df-json-shared-data
branch
from
November 10, 2026 18:20
c4706a8 to
759e181
Compare
joe-clickhouse
approved these changes
Nov 11, 2026
joe-clickhouse
left a comment
Contributor
There was a problem hiding this comment.
Thanks, approving. I merged main and updated docs/rust-codec.mdx, which listed this bug as a Python vs Rust difference.
The Rust codec doesn't have this bug, but Python is the default, so it's worth fixing there.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
JSON string formatting fails on decoded NumPy scalars with the standard-library serializer, requiring recursive conversion to Python values while preserving native object results and regression coverage for query_df and query_np.
1 open issue
What changed in this PR
Updates the Python codec to decode JSON shared data correctly in pandas and NumPy query results, addressing #1176.
Changes:
- Preserves raw bytes until decoding and retains valid
0andfalsevalues in JSON and Dynamic results. - Adds regression tests for scalar and nested JSON across query APIs and dtype options.
- Updates the changelog and documents remaining Python/Rust codec differences.
Validation was limited to code inspection; tests were not run.
| File | Description |
|---|---|
tests/integration_tests/test_dynamic.py |
Adds shared-data decoding and zero/false regression cases. |
docs/rust-codec.mdx |
Clarifies scalar-type and string-truncation differences between codecs. |
clickhouse_connect/datatypes/dynamic.py |
Preserves binary shared values and checks decoded result length. |
CHANGELOG.md |
Records the JSON and Dynamic decoding fixes. |
Review effort: Balanced
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.

Summary
Fixes #1176
JSON shared data is read as a
Map(String, String)whose value type isSharedDataString. That class reads raw bytes, but it inheritsString._finalize_column. Withuse_extended_dtypes, whichquery_dfuses by default, or withmax_str_len, the raw bytes become pandas or NumPy strings.decode_shared_data_valuethen sees astrand returns it unchanged, so the type byte and payload end up in the result.This change:
SharedDataString._finalize_columnthat returns the raw column, the same asSharedVariantalready does._decode_variantto checklen(result)instead ofresult. In NumPy mode the single decoded value is a one-element array, and0orFalsemade it falsy, so the value becameNone. This dropped0andfalsefrom JSON shared data and also turnedDynamic(max_types=0)values0andfalseintoNoneinquery_df.Not changed: with
max_str_len, shared data path names and string values are still cut to that length, and decoded numbers are NumPy scalars in NumPy and pandas results. Both come from decoding with the query context and were the same before. I kept this PR small, but I can follow up with a neutral decode context if you want.Tests:
tests/integration_tests/test_dynamic.pycoversJSON(max_dynamic_paths=0)as a scalar and insideArray,Map,TupleandArray(Tuple), with numbers, strings, floats, arrays, nested objects,0,falseand"", forquery,query_dfandquery_npwith and without extended dtypes andmax_str_len. It also adds0andfalseto theDynamicshared value DataFrame test. The new cases fail on main and pass with this change, through sync and async clients, withCLICKHOUSE_CONNECT_USE_C=0and1.Checklist