Handle NaN and null placeholders in JSON responses#45
Merged
Conversation
The cloud API stores NaN/Infinity as sentinel strings (e.g. "__NDI__NaN__") since JSON doesn't support these values natively. The MATLAB version calls rehydrateJSONNanNull to convert these back before use, but the Python version was missing this step. Documents downloaded from the cloud retained the placeholder strings instead of actual NaN/Infinity values. Apply rehydrateJSONNanNull in two places: - _download_chunk_zip: rehydrate raw JSON text from bulk-download ZIPs before json.loads - CloudClient._handle_response: rehydrate API response text before JSON parsing, so individual document fetches (e.g. getDocument) also get proper NaN/Infinity values https://claude.ai/code/session_0123bjBh3DEvxwphenpH1i1b
Remove four functions that corresponded to deleted MATLAB files: - dataset() + downloadFullDataset alias: old entry point that downloaded docs one-by-one and wrote them to disk as JSON files - datasetDocuments(): individual document download + JSON file save - setFileInfo(): file_info patching, now in sync layer (updateFileInfoForRemoteFiles in filehandler.py) The modern pipeline (downloadDocumentCollection → orchestration.downloadDataset) uses bulk ZIP download with proper NaN rehydration and returns documents in memory without a disk round-trip. Retained functions still used by orchestration.py: - downloadDocumentCollection, jsons2documents, structsToNdiDocuments, downloadDatasetFiles, downloadFilesForDocument, downloadGenericFiles https://claude.ai/code/session_0123bjBh3DEvxwphenpH1i1b
The MATLAB file +ndi/+cloud/+download/+internal/setFileInfo.m was deleted; remove it from the MATLAB equivalents list in the module docstring. https://claude.ai/code/session_0123bjBh3DEvxwphenpH1i1b
Python's IEEE 754 semantics make float('nan') != float('nan'), which
caused doc.diff to report spurious mismatches for document properties
containing NaN values. The MATLAB ndi.fun.dataset.diff was updated to
treat NaN == NaN; apply the same logic in the Python _compare helper.
https://claude.ai/code/session_0123bjBh3DEvxwphenpH1i1b
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
This PR adds support for rehydrating NaN and null placeholders in JSON responses from the NDI cloud API. JSON doesn't natively support NaN values, so the API uses placeholder strings that need to be converted back to proper JSON null values before parsing.
Key Changes
jsonimport tosrc/ndi/cloud/client.py_handle_response()inclient.pyto userehydrateJSONNanNull()utility function before parsing JSON responses_download_chunk_zip()indownload.pyto decode and rehydrate JSON text from zip file entries before parsingrehydrateJSONNanNullutility function indownload.pyImplementation Details
rehydrateJSONNanNull()function is called on the raw response text beforejson.loads()to convert placeholder strings back to valid JSON null valueshttps://claude.ai/code/session_0123bjBh3DEvxwphenpH1i1b