Skip to content

REGR: treat path-like objects with read/write but no __iter__ as paths - #71841

Closed
Xander-AJ wants to merge 3 commits into
pandas-dev:mainfrom
Xander-AJ:fix/stringify-path-pathlike-regression
Closed

Xander-AJ wants to merge 3 commits into
pandas-dev:mainfrom
Xander-AJ:fix/stringify-path-pathlike-regression

Conversation

@Xander-AJ

Copy link
Copy Markdown

#64986 dropped the __iter__ requirement from is_file_like, so stringify_path now treats any os.PathLike with read/write as an open buffer. py.path.local (pytest's tmpdir) has read()/write() helpers but isn't iterable, so it goes through as a buffer instead of through __fspath__. read_csv raises a TypeError (the C parser calls LocalPath.read(262144), whose first argument is mode), and to_csv silently keeps only the last chunk because LocalPath.write() rewrites the file each call.

I changed stringify_path so the GH 38125 shortcut doesn't apply to an os.PathLike that isn't iterable. Non-path-like objects without __iter__ are still accepted as buffers, which is what #64986 was for. The fsspec case from GH 38125 is unaffected; test_stringify_file_and_path_like still passes. Same condition @hamarshehmhmd suggested in the issue.

Added a stringify_path test and a to_csv/read_csv round trip with a small path-like class that has read/write and no __iter__. Both fail on main and pass with the fix. Also checked the original repro with _pytest._py.path.LocalPath.

I used Claude Code with Claude Opus 5.5 () to write the fix, tests and whatsnew entry and to run the tests and pre-commit. I reviewed every change myself.

  • I did not use AI to develop this pull request.
  • I used AI to develop this pull request. I prompted it to follow AGENTS.md, I have reviewed and understood every change, and I have described above how I used it and exactly which tool, model version, and effort setting.

@github-actions github-actions Bot added the Needs Issue Assignment PR whose author is not assigned to a linked issue label Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Thanks for the pull request, @Xander-AJ! It's linked to #71769, which is currently assigned to @thergupta2001, who's already working on it. We keep one contributor per issue to avoid duplicated effort. If @thergupta2001 has had no activity for 7 days, the issue is released automatically and you'll then be able to claim it with /take on #71769 — for now, please coordinate with them on the issue. See the contributing guide for details.

I've closed this pull request for now — none of your work is lost. Once #71769 is assigned to you, ask a maintainer to reopen it.

@github-actions github-actions Bot closed this Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Issue Assignment PR whose author is not assigned to a linked issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: read_csv fails with TypeError: open() argument 'mode' must be str, not int (with LocalPath)

1 participant