-
Notifications
You must be signed in to change notification settings - Fork 51
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
bugfix/fsspec-local-file-opener-cpp-buffer-for-czi #425
Conversation
The context here is that we generally can ignore the The change made in fsspec upstream simply changes the return type of |
Codecov Report
@@ Coverage Diff @@
## main #425 +/- ##
===========================================
+ Coverage 83.83% 94.03% +10.19%
===========================================
Files 46 46
Lines 3972 3972
===========================================
+ Hits 3330 3735 +405
+ Misses 642 237 -405
Continue to review full report at Codecov.
|
The change in fsspec was intentional, as the LocalFileOpened instances are serialisable, but the builtin python instances are not, so the previous behaviour was preventing pickle within a context. LocalFileOpener is a subclass of IOBase, not io.BufferedIOBase. Changing that might be reasonable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice find, quick fix!
I tried messing with the pybind11 code in |
@@ -95,7 +95,7 @@ def _is_supported_image(fs: AbstractFileSystem, path: str, **kwargs: Any) -> boo | |||
) | |||
|
|||
with fs.open(path) as open_resource: | |||
CziFile(open_resource) | |||
CziFile(open_resource.f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest making this a really small function that returns resource.f
so that the actual .f
part only shows up in one place. It's a minor thing that could help hide that implementation detail.
for example:
def get_file_handle(fs_local_opener):
return fs_local_opener.f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or maybe get_buffered_reader or whatever
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am going to merge without this. Returning an open buffer means we may have a open file handle down the line.
Would need to do something like:
def get_file_handle(fs, path):
yield fs.open(path).f
but that also doesn't ensure a closed handle after we are done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine w/that, but what's the difference between
with fs.open(path) as file:
CziFile(function_that_returns_file_dot_f(file))
and
with fs.open(path) as file:
CziFile(file.f)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't saying to wrap the with
part in a function. only the bit that calls .f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhhh that was my confusion. I thought you were asking for the with
/ context manager to be included. My mistake.
Description
Looks like one more thing snuck in on the recent
fsspec
releases. A change to the__enter__
behavior offsspec.local.LocalFileOpener
: fsspec/filesystem_spec@06c4003Pinging @martindurant to see if this is a verified "breaking change" or unintended.
Thanks for contributing!