Skip to content

fix(fileio): reset the Zemax parser state between encoding attempts - #1214

Merged
HarrisonKramer merged 1 commit into
optiland:masterfrom
jjohnnystwsss:fix/zemax-encoding-retry-state
Nov 23, 2026
Merged

HarrisonKramer merged 1 commit into
optiland:masterfrom
jjohnnystwsss:fix/zemax-encoding-retry-state

Conversation

@jjohnnystwsss

Copy link
Copy Markdown
Contributor

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.

Before fix After fix
Number of surfaces 14 9
Focal length nan 25
  • pytest tests/test_fileio/ (NumPy and PyTorch): 2049 passed.
  • Ruff checks passed.

Checklist

  • If this PR addresses an issue, I claimed it there first and nobody else had.
  • I have read the entire diff and can explain every change.
  • This PR is one logical change and is as small as it reasonably can be.
  • Tests are added or updated, and the relevant ones pass locally (NumPy and PyTorch where applicable).
  • Public API is unchanged, or the change was discussed in the linked issue.
  • Docs and docstrings are updated where needed.

AI assistance

  • No AI tools were used.
  • AI tools helped (tool: Claude Code). I reviewed, ran, and understand all of the output.

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

codecov Bot commented Nov 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@HarrisonKramer

Copy link
Copy Markdown
Collaborator

Thanks @jjohnnystwsss, nice catch on the chunked decode. Merging this.

@HarrisonKramer
HarrisonKramer merged commit 37843c4 into optiland:master Nov 23, 2026
17 checks passed
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.

2 participants