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

FIX: Raise NotImplementedError if user passes an open file handle to write #442

Merged
merged 4 commits into from
Jul 9, 2024

Conversation

brendan-ward
Copy link
Member

As indicated in #430 and geopandas #3369, if a user passed an open file handle to write, we were failing with confusing error messages. While the docstrings in pyogrio specify the allowed inputs, we weren't strictly verifying those, and so any path that was not BytesIO was first getting cast to a string, and then failing badly from there.

These usages worked for users with the Fiona engine (previous default) in GeoPandas, so it is proving to be a point of confusion now that Pyogrio is the default engine and things are no longer working as expected.

In most cases, writing the dataset to BytesIO and then writing those bytes to the file handle (regular file handle via open, an fsspec opened file handle, or an open handle within a ZipFile), so the error message includes a brief instruction to do that instead. That also helps defer catching issues around supported drivers and lack of append support to the BytesIO handler.

In the mid term, we may be able to detect that the user passed a writeable file handle, and wrap in BytesIO ourselves, but this is more involved than I had time to take on at the moment.

Copy link
Member

@theroggy theroggy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@brendan-ward brendan-ward merged commit 7949dff into main Jul 9, 2024
20 checks passed
@brendan-ward brendan-ward deleted the raise_file_write_not_implemented branch July 9, 2024 17:47
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.

2 participants