Repository navigation
fix(fileio): reset the Zemax parser state between encoding attempts - #1214
Merged
HarrisonKramer merged 1 commit intoNov 23, 2026
Merged
Conversation
The UTF-8 attempt decoded the file in chunks, so a Latin-1 file with a non-ASCII byte past the first 8 KiB failed only after some lines were parsed, and the ISO-8859-1 retry added those surfaces again. Decode the whole file before parsing and start each attempt from a clean state. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Collaborator
|
Thanks @jjohnnystwsss, nice catch on the chunked decode. Merging this. |
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
I found that when importing a Latin-1 Zemax file with a non-ASCII byte after the first 8 KiB chunk, the UTF-8 decoding can fail after some surfaces are already parsed. When retrying with another encoding, the parser still keeps the surfaces from the failed attempt, so some surfaces are added twice. I fixed this by decoding the whole file before parsing and adding
_reset_state()to reset the parser state before each attempt.Related issue
No related issue, this is a small bug fix.
How I verified this
I tested a Latin-1 Zemax file with a non-ASCII character after the first 8 KiB chunk.
nanpytest tests/test_fileio/(NumPy and PyTorch): 2049 passed.Checklist
AI assistance