Skip to content

Fix UTF-8 text I/O in fsspec backend - #822

Open
mukeshr06 wants to merge 1 commit into
google:mainfrom
mukeshr06:fix/fsspec-utf8-encoding
Open

mukeshr06 wants to merge 1 commit into
google:mainfrom
mukeshr06:fix/fsspec-utf8-encoding

Conversation

@mukeshr06

Copy link
Copy Markdown

Problem

Backend.open() promises UTF-8 text I/O, and the OS backend explicitly uses UTF-8. The fsspec backend currently omits the encoding, so fsspec falls back to the system locale. On non-UTF-8 systems this can reject non-ASCII text or decode UTF-8 files incorrectly.

Change

Pass encoding='utf-8' for fsspec text modes and None for binary modes. Add regression coverage for reading, writing, appending, and exclusive creation in text and binary modes.

Fixes #817.

Validation

A focused regression run using fsspec's local filesystem produced 8 Unicode failures with the previous implementation and passed all 12 cases with this change.

The full pytest suite was not run locally because the test dependency download timed out; CI should provide the complete validation.

@mukeshr06

Copy link
Copy Markdown
Author

Additional validation on fade86d with Python 3.12.14 and fsspec 2026.9.0:

  • All 12 new UTF-8/binary regressions pass
  • Backend suite: 30 passed, 154 subtests passed
  • Epath suite: 79 passed, 154 subtests passed, with two tests excluded

Exclusions:

  • gpath_test.py::test_use_backend assumes TensorFlow is installed
  • gpath_test.py::test_public_access requires live public GCS access, which was not exercised

A run without these exclusions on base 8c94567 failed the same two tests in the minimal environment, with 67 tests and 154 subtests passing. Restoring the previous open implementation also caused all eight UTF-8 regressions to fail while the four binary tests continued to pass.

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.

_FileSystemSpecBackend.open() ignores the utf-8 contract stated in Backend.open()

1 participant