-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: do not stringify file-like objects #38141
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,6 +152,7 @@ def validate_header_arg(header) -> None: | |
|
||
def stringify_path( | ||
filepath_or_buffer: FilePathOrBuffer[AnyStr], | ||
convert_file_like: bool = False, | ||
) -> FileOrBuffer[AnyStr]: | ||
""" | ||
Attempt to convert a path-like object to a string. | ||
|
@@ -169,12 +170,15 @@ def stringify_path( | |
Objects supporting the fspath protocol (python 3.6+) are coerced | ||
according to its __fspath__ method. | ||
|
||
For backwards compatibility with older pythons, pathlib.Path and | ||
py.path objects are specially coerced. | ||
|
||
Any other object is passed through unchanged, which includes bytes, | ||
strings, buffers, or anything else that's not even path-like. | ||
""" | ||
if not convert_file_like and is_file_like(filepath_or_buffer): | ||
# GH 38125: some fsspec objects implement os.PathLike but have already opened a | ||
# file. This prevents opening the file a second time. infer_compression calls | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in a followup if can try to remove the incompatible return issue here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure whether that is possible: the function is supposed to not return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, sorry: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah would not like to add the typing comment (so pls update) and ping on green There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay, I thought I saw some issue to add these comments whenever mypy warning are ignored. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure but ideally we do not want to ignore instead do the proper asserts that mypy is happy putting in the commrnts is just a temporary patch |
||
# this function with convert_file_like=True to infer the compression. | ||
return cast(FileOrBuffer[AnyStr], filepath_or_buffer) | ||
|
||
if isinstance(filepath_or_buffer, os.PathLike): | ||
filepath_or_buffer = filepath_or_buffer.__fspath__() | ||
return _expand_user(filepath_or_buffer) | ||
|
@@ -462,7 +466,7 @@ def infer_compression( | |
# Infer compression | ||
if compression == "infer": | ||
# Convert all path types (e.g. pathlib.Path) to strings | ||
filepath_or_buffer = stringify_path(filepath_or_buffer) | ||
filepath_or_buffer = stringify_path(filepath_or_buffer, convert_file_like=True) | ||
if not isinstance(filepath_or_buffer, str): | ||
# Cannot infer compression of a buffer, assume no compression | ||
return None | ||
|
Uh oh!
There was an error while loading. Please reload this page.