-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX: Support UTF-8 encoding for JSON files #1357
Open
scott-huberty
wants to merge
6
commits into
mne-tools:main
Choose a base branch
from
scott-huberty:fix_json_encoding
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains 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
scott-huberty
changed the title
WIP: add ensure_ascii parameter to _write_json
WIP: Support UTF-8 encoding for JSON files
Dec 19, 2024
I don't think we want to convert to ASCII for any JSON we're writing to disk. Hence, we don't need a parameter to control this behavior :) |
This reverts commit 4c47679.
TIL: That json.loads will always convert unicode. So to test that unicode was properly encoded while writing to disk, I had to had to just read the text on disk without the json module
hoechenberger
approved these changes
Dec 20, 2024
drammock
approved these changes
Dec 20, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, nice adaptation of the existing test. One suggested improvement, see below
Instead of closing and re-opening the file, rewind the "playhead" to the start of the open file, then use fid.read() as usual Co-authored-by: Daniel McCloy <dan@mccloy.info>
scott-huberty
changed the title
WIP: Support UTF-8 encoding for JSON files
FIX: Support UTF-8 encoding for JSON files
Dec 20, 2024
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 #1356
_write_json
is used a lot in the MNE-BIDS codebase... I want to get your feedback on whether adding a new parameterensure_ascii=False
to_write_tsv
is the right way to go?Because I'm not sure if there are cases in MNE-BIDS where we do want to enforce ASCII encoding during JSON writing.. If so, we could change the default to
ensure_ascii=True
, and passFalse
explicitly for the cases where we want to support UTF-8?cc @sappelhoff @hoechenberger @larsoner
TODO