Skip to content
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

Improve fsspec.open Code Snippet for Better Compatibility #123

Merged
merged 3 commits into from
Mar 26, 2025

Conversation

danyeaw
Copy link
Contributor

@danyeaw danyeaw commented Mar 20, 2025

Closes #115.

Changes

Updates the Insert open Code Snippet to:

  • Use binary mode ("rb") instead of text mode ("rt")
  • Replace iteration with ... (pass) to give a place for you to write your code without an error
  • Fix typos with the response body for some of the neighboring tests

Before:

with fsspec.open("file:///My/file/path/CHANGE_LOG.md", "rt") as f:
   for line in f:
      print(line)

After:

with fsspec.open("file:///My/file/path/CHANGE_LOG.md", "rb") as f:
   ...

Rationale

  • Improved compatibility**: Binary mode works with both text and binary files
  • Prevents errors: For-loop iteration over non-text files (like parquet) would fail

@martindurant
Copy link
Member

Perhaps instead of print(f.readline()) have simply ... ?

Note that the snippet is not actually useful without kwargs in many cases (e.g., even anon=True for s3). Passing the kwargs to the client was suggested first in #113 , and now included in #116 as soon as @RRosio pushes her work.

@danyeaw
Copy link
Contributor Author

danyeaw commented Mar 20, 2025

Hi @martindurant, good idea, I updated the PR with ....

Nice, those sound like some nice updates on the way!

@RRosio RRosio added the maintenance General tasks for project upkeep label Mar 26, 2025
@RRosio RRosio merged commit 12b4ea5 into fsspec:main Mar 26, 2025
7 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance General tasks for project upkeep
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Open with block should correctly detect filetype
3 participants