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

Not possible to read from file handles without warnings #508

Open
vilim opened this issue Dec 17, 2024 · 4 comments
Open

Not possible to read from file handles without warnings #508

vilim opened this issue Dec 17, 2024 · 4 comments

Comments

@vilim
Copy link

vilim commented Dec 17, 2024

Reading files with the method:

with open(file, "rb") as f:
    pyogrio.read_dataframe(f)

always raises a warning like:

/home/vstih/.conda/envs/detektp/lib/python3.11/site-packages/pyogrio/raw.py:198: RuntimeWarning:

File [/vsimem/pyogrio_c99dcda56d63460497ec381f7b73f788](http://localhost:8810/vsimem/pyogrio_c99dcda56d63460497ec381f7b73f788) has GPKG application_id, but non conformant file extension

I am using pyogrio version 0.10.0
if a byte stream is passed to read_dataframe, I guess the warning should not be raised.

@brendan-ward
Copy link
Member

The error comes from GDAL; it is trying to enforce file name conventions for GPKG files. The problem here is that we pass off a byte stream which contains the bytes of the GPKG and a randomly-generated filename without extension, but we don't currently detect that it is a GPKG file on our end in order to add the correct extension. I recall that with GPKG it is a little tricky; we can read the first few bytes to determine that it is an SQLite file, but I think GDAL does several more heuristics to determine that it is indeed a GPKG.

I guess the other thing we could do is specifically ignore this warning internally when we know we are using bytes instead of a file path.

@Juanouo
Copy link

Juanouo commented Mar 21, 2025

I'm having the same issue. Is there any way I can silence the warning?

@theroggy
Copy link
Member

You can filter it like any warning, e.g. like this:

import warnings

import pyogrio

file = "C:\Temp\polygon_parcel\polygon-parcel.gpkg"

with open(file, "rb") as f:
    with warnings.catch_warnings():
        warnings.filterwarnings("ignore", ".*has GPKG application_id.*", RuntimeWarning)
        pyogrio.read_dataframe(f)

@jorisvandenbossche
Copy link
Member

I guess the other thing we could do is specifically ignore this warning internally when we know we are using bytes instead of a file path.

I think this would be a good (at least temporary / short-term) solution to avoid users seeing this warning

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

No branches or pull requests

5 participants