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

ENH: Writing to in-memory multilayer GPKGs #2875

Open
AdnanAvdagic opened this issue Apr 20, 2023 · 16 comments
Open

ENH: Writing to in-memory multilayer GPKGs #2875

AdnanAvdagic opened this issue Apr 20, 2023 · 16 comments

Comments

@AdnanAvdagic
Copy link

AdnanAvdagic commented Apr 20, 2023

Is your feature request related to a problem?

In my company we use a postgis database where we host all of our customers data. We then allow our customers to export this as any number of file formats, including GPKG. The issue is that we cannot use pythons IO.BytesIO in-memory files if we want multiple layers in the exported GPKG file and we would like not to have to write to disk.

Describe the solution you'd like

Is there any way for geopandas to write to in-memory multilayer GPKGs so they can be sent from the webserver?

API breaking implications

No idea if it breaks anything.

Describe alternatives you've considered

The alternative is creating a temp file on disk and writing to that

Additional context

tmp_file = io.BytesIO()
gdf.to_file(tmp_file, driver="GPKG", layer=name)
@AdnanAvdagic AdnanAvdagic changed the title ENH: ENH: Writing to in-memory multilayer GPKGs Apr 20, 2023
@m-richards
Copy link
Member

m-richards commented Apr 24, 2023

Hi @AdnanAvdagic this certainly seems like something that we could support. A PR would definitely be welcome if you're interested! Having a quick look in the fiona case, I'm seeing something different to you.

gdf = gpd.GeoDataFrame(gpd.read_file(gpd.datasets.get_path("nybb")))
tmp_file = io.BytesIO()
gdf.to_file(tmp_file,driver="GPKG")
gdf2 = gpd.read_file(tmp_file)
  File "C:\Users\Matt\.conda\envs\pandas-dev\lib\site-packages\fiona\collection.py", line 162, in __init__
    self.session.start(self, **kwargs)
  File "fiona\ogrext.pyx", line 540, in fiona.ogrext.Session.start
  File "fiona\_shim.pyx", line 90, in fiona._shim.gdal_open_vector
fiona.errors.DriverError: '/vsimem/ec35a40572b84db6bb280bf285beea47' not recognized as a supported file format.

I get an error on read instead in my local environment (with fiona 1.8.22).

But this seems to be in the geopandas wrapping of fiona. I'll try have a look in more detail at some point.

There is also another crash if driver=None for io.BytesIO which we should handle better.

@jorisvandenbossche
Copy link
Member

@m-richards I think when writing to a in-memory file like object, and then if you want to read it back, you have to put the "current position" back to the start of the object. This works for me:

gdf = geopandas.read_file(geopandas.datasets.get_path("nybb"))

tmp_file = io.BytesIO()
gdf.to_file(tmp_file, driver="GPKG")
# this line is needed
tmp_file.seek(0)

In [20]: geopandas.read_file(tmp_file)
Out[20]: 
   BoroCode       BoroName     Shape_Leng    Shape_Area                                           geometry
0         5  Staten Island  330470.010332  1.623820e+09  MULTIPOLYGON (((970217.022 145643.332, 970227....
1         4         Queens  896344.047763  3.045213e+09  MULTIPOLYGON (((1029606.077 156073.814, 102957...
2         3       Brooklyn  741080.523166  1.937479e+09  MULTIPOLYGON (((1021176.479 151374.797, 102100...
3         1      Manhattan  359299.096471  6.364715e+08  MULTIPOLYGON (((981219.056 188655.316, 980940....
4         2          Bronx  464392.991824  1.186925e+09  MULTIPOLYGON (((1012821.806 229228.265, 101278...

So this works for a single layer. The question is now if this can also work with multiple layers. Testing naively writing to the same buffer doesn't work:

df = geopandas.GeoDataFrame({"col": [1, 2], "geometry": geopandas.points_from_xy([1, 2], [1, 2])})
df1 = df.iloc[:1]
df2 = df.iloc[1:]

tmp_file = io.BytesIO()
df1.to_file(tmp_file, driver="GPKG", layer="layer1")
# it doesn't work neither with or without the following line
# tmp_file.seek(0)
df2.to_file(tmp_file, driver="GPKG", layer="layer2")

tmp_file.seek(0)
geopandas.read_file(tmp_file, layer="layer1")

tmp_file.seek(0)
geopandas.read_file(tmp_file, layer="layer2")
# -> ValueError: Null layer: 'layer2'

Checking with pyogrio confirms that the file only has the first layer:

tmp_file.seek(0)
pyogrio.list_layers(tmp_file)
# -> array([['layer1', 'Point']], dtype=object)

For normal files, you don't have to explicitly say to append, if you write to a geopackage file that already exist, it will automatically add a new layer (if you provide a different name, or otherwise overwrite the layer, I suppose).
But when explicitly asking to append, fiona raises an error that this isn't supported for in-memory file-like objects:

tmp_file = io.BytesIO()
df1.to_file(tmp_file, driver="GPKG", layer="layer1")
tmp_file.seek(0)
df2.to_file(tmp_file, driver="GPKG", layer="layer2", mode="a")
# -> OSError: Append mode is not supported for datasets in a Python file object.

So with would need some more investigation if this could be possible with either fiona or pyogrio.

@theroggy
Copy link
Member

theroggy commented Apr 29, 2023

Funny, apparently I was also having a look at this at the same time as @jorisvandenbossche :-)...

I tried if it would be possible using the "vsimem" feature of gdal, but it seems that the 2nd layer isn't added to the memory geopackage, but the geopackage is just overwritten. Based on a quick scan of the code in pyogrio it should work, and when the path is a real file it works fine, so I suppose the issue (or the fact that it isn't supported) is in gdal:

import pyogrio
import geopandas as gpd
from osgeo import gdal

gdf = gpd.GeoDataFrame(gpd.read_file(gpd.datasets.get_path("nybb")))

memfile_path = "/vsimem/memoryfile.gpkg"
# memfile_path = "C:/temp/memoryfile.gpkg"
try:
    gdf.iloc[[0, 1]].to_file(memfile_path, driver="GPKG", layer="test1" , engine="pyogrio")
    layers = pyogrio.list_layers(memfile_path)
    gdf.iloc[[2, 3]].to_file(memfile_path, driver="GPKG", layer="test2" , engine="pyogrio")
    layers = pyogrio.list_layers(memfile_path)
    print(layers)
    gdf1 = gpd.read_file(memfile_path, driver="GPKG", layer="test1")
    gdf2 = gpd.read_file(memfile_path, driver="GPKG", layer="test2")
    print(gdf1)
    print(gdf2)
finally:
    gdal.Unlink(memfile_path)

@jorisvandenbossche
Copy link
Member

I think that for pyogrio, we actually don't yet support writing to an in-memory BytesIO or /vsimem at all (also not for a single file / layer). Opened geopandas/pyogrio#249 for this

@m-richards
Copy link
Member

Thanks both for clarifying this, I don't use BytesIO very often and it clearly shows

@fgashakamba
Copy link

I am trying to see if this has implication for someone who wants to download a geopackage file from a geodataframe in shiny.
I tried this code:

    @session.download(filename="my_route.gpkg")
    def downloadRoute():
        result_value = result()
        route = result_value['route_detailed']
        tmp_file = io.BytesIO()
        route.to_file(tmp_file, driver="GPKG")
        tmp_file.seek(0)
        yield tmp_file.read()

...and it is resulting in this error:

File "pyogrio\_io.pyx", line 1437, in pyogrio._io.ogr_write
    |   File "pyogrio\_io.pyx", line 1277, in pyogrio._io.ogr_create
    | pyogrio.errors.DataSourceError: sqlite3_open(<_io.BytesIO object at 0x0000019D5F769CB0>) failed: unable to open database file     

@brendan-ward
Copy link
Member

@fgashakamba what is the result of running geopandas.show_versions()

Writing to BytesIO was added in pyogrio 0.8.0

@fgashakamba
Copy link

@brendan-ward I have geopandas 0.14.2 installed.

@theroggy
Copy link
Member

theroggy commented Jul 30, 2024

@brendan-ward I have geopandas 0.14.2 installed.

@fgashakamba best post the entire output of geopandas.show_versions(): brendan would probably (also) want to know the version being reported for pyogrio.

@fgashakamba
Copy link

fgashakamba commented Jul 30, 2024

Hello @brendan-ward and @theroggy
Here is the whole output of the gpd.show.versions():

SYSTEM INFO
-----------
python     : 3.11.9 | packaged by Anaconda, Inc. | (main, Apr 19 2024, 16:40:41) [MSC v.1916 64 bit (AMD64)]
executable : C:\Anaconda\envs\geospatial\python.exe
machine    : Windows-10-10.0.22631-SP0

GEOS, GDAL, PROJ INFO
---------------------
GEOS       : 3.11.1
GEOS lib   : None
GDAL       : None
GDAL data dir: None
PROJ       : 9.1.1
PROJ data dir: C:\Anaconda\envs\geospatial\Library\share\proj

PYTHON DEPENDENCIES
-------------------
geopandas  : 0.14.2
numpy      : 1.26.4
pandas     : 2.2.2
pyproj     : 3.5.0
shapely    : 2.0.1
fiona      : None
geoalchemy2: None
geopy      : None
matplotlib : 3.8.4
mapclassify: 2.5.0
pygeos     : None
pyogrio    : None
psycopg2   : None
pyarrow    : 14.0.2
rtree      : 1.0.1

@brendan-ward
Copy link
Member

That doesn't seem right; it shows neither fiona nor pyogrio installed, which should raise an error on .to_file(). Further, your exception log above indicates it was failing inside pyogrio, so clearly it was installed in whatever environment you were using for that example. Can you please use that environment (where pyogrio is available) and then tell us the version of pyogrio?

This will also work:

import pyogrio
print(pyogrio.__version__)

@fgashakamba
Copy link

@brendan-ward
I am puzzled too as to why gpd.show_versions() hints that pyogrio is not installed. In the conda environment I am using, this package and fiona both exist.
Running print(pyogrio.__version__) shows that the version I have is 0.5.1

@theroggy
Copy link
Member

Can you also post the output of conda list for this environment?

@fgashakamba
Copy link

Can you also post the output of conda list for this environment?

Sure. Here is the output of conda list in the environment I am using:

# packages in environment at C:\Anaconda\envs\geospatial:
#
# Name                    Version                   Build  Channel
abseil-cpp                20211102.0           hd77b12b_0
affine                    2.4.0              pyhd8ed1ab_0    conda-forge
altair                    5.0.1           py311haa95532_0
anyio                     4.2.0           py311haa95532_0
appdirs                   1.4.4              pyhd3eb1b0_0
argon2-cffi               21.3.0             pyhd3eb1b0_0
argon2-cffi-bindings      21.2.0          py311h2bbff1b_0
arrow-cpp                 14.0.2               ha81ea56_1
asgiref                   3.5.2           py311haa95532_0
asttokens                 2.0.5              pyhd3eb1b0_0
async-lru                 2.0.4           py311haa95532_0
attrs                     23.1.0          py311haa95532_0
aws-c-auth                0.6.19               h2bbff1b_0
aws-c-cal                 0.5.20               h2bbff1b_0
aws-c-common              0.8.5                h2bbff1b_0
aws-c-compression         0.2.16               h2bbff1b_0
aws-c-event-stream        0.2.15               hd77b12b_0
aws-c-http                0.6.25               h2bbff1b_0
aws-c-io                  0.13.10              h2bbff1b_0
aws-c-mqtt                0.7.13               h2bbff1b_0
aws-c-s3                  0.1.51               h2bbff1b_0
aws-c-sdkutils            0.1.6                h2bbff1b_0
aws-checksums             0.1.13               h2bbff1b_0
aws-crt-cpp               0.18.16              hd77b12b_0
aws-sdk-cpp               1.10.55              hd77b12b_0
babel                     2.11.0          py311haa95532_0
beautifulsoup4            4.12.3          py311haa95532_0
blas                      1.0                         mkl
bleach                    4.1.0              pyhd3eb1b0_0
blinker                   1.6.2           py311haa95532_0
blosc                     1.21.3               h6c2663c_0
boost-cpp                 1.82.0               h59b6b97_2
bottleneck                1.3.7           py311hd7041d2_0
branca                    0.6.0           py311haa95532_0
brotli                    1.0.9                h2bbff1b_8
brotli-bin                1.0.9                h2bbff1b_8
brotli-python             1.0.9           py311hd77b12b_8
bzip2                     1.0.8                h2bbff1b_6
c-ares                    1.19.1               h2bbff1b_0
ca-certificates           2024.7.4             h56e8100_0    conda-forge
cachetools                5.3.3           py311haa95532_0
cairo                     1.16.0               haedb8bc_5
certifi                   2024.7.4        py311haa95532_0
cffi                      1.16.0          py311h2bbff1b_1
cfitsio                   4.2.0                h9ebe7e4_0    conda-forge
charset-normalizer        2.0.4              pyhd3eb1b0_0
click                     8.1.7           py311haa95532_0
click-plugins             1.1.1              pyhd3eb1b0_0
cligj                     0.7.2              pyhd3eb1b0_0
colorama                  0.4.6           py311haa95532_0
comm                      0.2.1           py311haa95532_0
contourpy                 1.2.0           py311h59b6b97_0
curl                      8.7.1                he2ea4bf_0
cycler                    0.11.0             pyhd3eb1b0_0
debugpy                   1.6.7           py311hd77b12b_0
decorator                 5.1.1              pyhd3eb1b0_0
defusedxml                0.7.1              pyhd3eb1b0_0
executing                 0.8.3              pyhd3eb1b0_0
expat                     2.6.2                hd77b12b_0
fiona                     1.9.5           py311hf62ec03_0
folium                    0.17.0             pyhd8ed1ab_0    conda-forge
fontconfig                2.14.2               hbde0cde_0    conda-forge
fonttools                 4.51.0          py311h2bbff1b_0
freetype                  2.12.1               ha860e81_0
freexl                    1.0.6                h67ca5e6_1    conda-forge
gdal                      3.6.2           py311h4bd9738_4    conda-forge
geopandas                 0.14.2          py311haa95532_0
geopandas-base            0.14.2          py311haa95532_0
geos                      3.11.1               h1537add_0    conda-forge
geotiff                   1.7.1                hc256dc0_6    conda-forge
gettext                   0.22.5               h5728263_2    conda-forge
gettext-tools             0.22.5               h7d00a51_2    conda-forge
gflags                    2.2.2                hd77b12b_1
gitdb                     4.0.7              pyhd3eb1b0_0
gitpython                 3.1.37          py311haa95532_0
glib                      2.78.1               h12be248_0    conda-forge
glib-tools                2.78.1               h12be248_0    conda-forge
glog                      0.5.0                hd77b12b_1
grpc-cpp                  1.48.2               hfe90ff0_1
h11                       0.14.0          py311haa95532_0
hdf4                      4.2.15               h1b1b6ef_5    conda-forge
hdf5                      1.12.2          nompi_h57737ce_101    conda-forge
htmltools                 0.5.2              pyhd8ed1ab_0    conda-forge
icc_rt                    2022.1.0             h6049295_2
icu                       70.1                 h0e60522_0    conda-forge
idna                      3.7             py311haa95532_0
intel-openmp              2023.1.0         h59b6b97_46320
ipykernel                 6.28.0          py311haa95532_0
ipyleaflet                0.19.1             pyhd8ed1ab_0    conda-forge
ipython                   8.25.0          py311haa95532_0
ipython_genutils          0.2.0              pyhd3eb1b0_1
ipywidgets                7.8.1           py311haa95532_0
jedi                      0.18.1          py311haa95532_1
jinja2                    3.1.4           py311haa95532_0
joblib                    1.4.2           py311haa95532_0
jpeg                      9e                   h2bbff1b_1
json5                     0.9.6              pyhd3eb1b0_0
jsonschema                4.19.2          py311haa95532_0
jsonschema-specifications 2023.7.1        py311haa95532_0
jupyter-lsp               2.2.0           py311haa95532_0
jupyter_client            8.6.0           py311haa95532_0
jupyter_core              5.7.2           py311haa95532_0
jupyter_events            0.10.0          py311haa95532_0
jupyter_leaflet           0.19.1             pyhd8ed1ab_0    conda-forge
jupyter_server            2.14.1          py311haa95532_0
jupyter_server_terminals  0.4.4           py311haa95532_1
jupyterlab                4.0.11          py311haa95532_0
jupyterlab_pygments       0.1.2                      py_0
jupyterlab_server         2.25.1          py311haa95532_0
jupyterlab_widgets        1.0.0              pyhd3eb1b0_1
kealib                    1.5.0                h61be68b_0    conda-forge
kiwisolver                1.4.4           py311hd77b12b_0
krb5                      1.21.2               heb0366b_0    conda-forge
lcms2                     2.12                 h83e58a3_0
lerc                      4.0.0                h63175ca_0    conda-forge
libaec                    1.1.3                h63175ca_0    conda-forge
libasprintf               0.22.5               h5728263_2    conda-forge
libasprintf-devel         0.22.5               h5728263_2    conda-forge
libboost                  1.82.0               h3399ecb_2
libbrotlicommon           1.0.9                h2bbff1b_8
libbrotlidec              1.0.9                h2bbff1b_8
libbrotlienc              1.0.9                h2bbff1b_8
libcurl                   8.7.1                h86230a5_0
libdeflate                1.17                 h2bbff1b_1
libevent                  2.1.12               h56d1f94_1
libffi                    3.4.4                hd77b12b_1
libgdal                   3.6.2                h8c89b76_4    conda-forge
libgettextpo              0.22.5               h5728263_2    conda-forge
libgettextpo-devel        0.22.5               h5728263_2    conda-forge
libglib                   2.78.1               he8f3873_0    conda-forge
libiconv                  1.17                 hcfcfb64_2    conda-forge
libintl                   0.22.5               h5728263_2    conda-forge
libintl-devel             0.22.5               h5728263_2    conda-forge
libkml                    1.3.0                h63940dd_7
libnetcdf                 4.8.1           nompi_h8c042bf_106    conda-forge
libpng                    1.6.39               h8cc25b3_0
libpq                     15.7                 h94c9ec1_0    conda-forge
libprotobuf               3.20.3               h23ce68f_0
librttopo                 1.1.0               he22b5cd_12    conda-forge
libsodium                 1.0.18               h62dcd97_0
libspatialindex           1.9.3                h6c2663c_0
libspatialite             5.0.1               hfdcade0_23    conda-forge
libsqlite                 3.46.0               h2466b09_0    conda-forge
libssh2                   1.11.0               h291bd65_0
libthrift                 0.15.0               h4364b78_2
libtiff                   4.5.0                hf8721a0_2    conda-forge
libwebp-base              1.3.2                h2bbff1b_0
libxml2                   2.12.7               h283a6d9_1    conda-forge
libzip                    1.10.1               h1d365fa_3    conda-forge
libzlib                   1.2.13               h2466b09_6    conda-forge
linkify-it-py             2.0.0           py311haa95532_0
lz4-c                     1.9.4                h2bbff1b_1
mapclassify               2.5.0           py311haa95532_0
markdown-it-py            2.2.0           py311haa95532_1
markupsafe                2.1.3           py311h2bbff1b_0
matplotlib-base           3.8.4           py311hf62ec03_0
matplotlib-inline         0.1.6           py311haa95532_0
mdit-py-plugins           0.3.0           py311haa95532_0
mdurl                     0.1.0           py311haa95532_0
minizip                   4.0.3                hb68bac4_0
mistune                   2.0.4           py311haa95532_0
mkl                       2023.1.0         h6b88ed4_46358
mkl-service               2.4.0           py311h2bbff1b_1
mkl_fft                   1.3.8           py311h2bbff1b_0
mkl_random                1.2.4           py311h59b6b97_0
nbclient                  0.8.0           py311haa95532_0
nbconvert                 7.10.0          py311haa95532_0
nbformat                  5.9.2           py311haa95532_0
nest-asyncio              1.6.0           py311haa95532_0
networkx                  3.2.1           py311haa95532_0
notebook                  7.0.8           py311haa95532_0
notebook-shim             0.2.3           py311haa95532_0
numexpr                   2.8.7           py311h1fcbade_0
numpy                     1.26.4          py311hdab7c0b_0
numpy-base                1.26.4          py311hd01c5d8_0
openjpeg                  2.5.0                ha2aaf27_2    conda-forge
openrouteservice          2.3.3                    pypi_0    pypi
openssl                   3.3.1                h2466b09_2    conda-forge
orc                       1.7.4                h623e30f_1
overrides                 7.4.0           py311haa95532_0
packaging                 23.2            py311haa95532_0
pandas                    2.2.2           py311hea22821_0
pandocfilters             1.5.0              pyhd3eb1b0_0
parso                     0.8.3              pyhd3eb1b0_0
pcre2                     10.40                h17e33f8_0    conda-forge
pillow                    10.3.0          py311h2bbff1b_0
pip                       24.0            py311haa95532_0
pixman                    0.40.0               h2bbff1b_1
platformdirs              3.10.0          py311haa95532_0
polyline                  2.0.2              pyhd8ed1ab_0    conda-forge
poppler                   22.12.0              h0bf3bde_3
poppler-data              0.4.11               haa95532_1
postgresql                15.7                 h94c9ec1_0    conda-forge
proj                      9.1.1                heca977f_2    conda-forge
prometheus_client         0.14.1          py311haa95532_0
prompt-toolkit            3.0.43          py311haa95532_0
prompt_toolkit            3.0.43               hd3eb1b0_0
protobuf                  3.20.3          py311hd77b12b_0
psutil                    5.9.0           py311h2bbff1b_0
pure_eval                 0.2.2              pyhd3eb1b0_0
pyarrow                   14.0.2          py311h847bd2a_0
pybind11-abi              5                    hd3eb1b0_0
pycparser                 2.21               pyhd3eb1b0_0
pydeck                    0.8.0           py311haa95532_2
pygments                  2.15.1          py311haa95532_1
pyogrio                   0.5.1           py311h73f1ccd_0    conda-forge
pyparsing                 3.0.9           py311haa95532_0
pyproj                    3.5.0           py311h36482e4_0    conda-forge
pysocks                   1.7.1           py311haa95532_0
python                    3.11.9               he1021f5_0
python-dateutil           2.9.0post0      py311haa95532_2
python-fastjsonschema     2.16.2          py311haa95532_0
python-json-logger        2.0.7           py311haa95532_0
python-multipart          0.0.6           py311haa95532_0
python-tzdata             2023.3             pyhd3eb1b0_0
python_abi                3.11                    2_cp311    conda-forge
pytz                      2024.1          py311haa95532_0
pywin32                   305             py311h2bbff1b_0
pywinpty                  2.0.10          py311h5da7b33_0
pyyaml                    6.0.1           py311h2bbff1b_0
pyzmq                     25.1.2          py311hd77b12b_0
qhull                     2020.2               h59b6b97_2
questionary               2.0.1              pyhd8ed1ab_0    conda-forge
rasterio                  1.3.6           py311hc06ee40_0    conda-forge
re2                       2022.04.01           hd77b12b_0
referencing               0.30.2          py311haa95532_0
requests                  2.32.2          py311haa95532_0
rfc3339-validator         0.1.4           py311haa95532_0
rfc3986-validator         0.1.1           py311haa95532_0
rich                      13.3.5          py311haa95532_0
rpds-py                   0.10.6          py311h062c2fa_0
rtree                     1.0.1           py311h2eaa2aa_0
scikit-learn              1.4.2           py311hf62ec03_1
scipy                     1.13.1          py311h9f229c6_0
send2trash                1.8.2           py311haa95532_0
setuptools                69.5.1          py311haa95532_0
shapely                   2.0.1           py311habfe8a2_0    conda-forge
shiny                     0.10.2             pyhd8ed1ab_0    conda-forge
shinywidgets              0.3.2              pyhd8ed1ab_0    conda-forge
six                       1.16.0             pyhd3eb1b0_1
smmap                     4.0.0              pyhd3eb1b0_0
snappy                    1.1.10               h6c2663c_1
sniffio                   1.3.0           py311haa95532_0
snuggs                    1.4.7                      py_0    conda-forge
soupsieve                 2.5             py311haa95532_0
sqlite                    3.45.3               h2bbff1b_0
stack_data                0.2.0              pyhd3eb1b0_0
starlette                 0.27.0          py311haa95532_0
streamlit                 1.32.0          py311haa95532_0
streamlit-folium          0.21.0                   pypi_0    pypi
tbb                       2021.8.0             h59b6b97_0
tenacity                  8.2.2           py311haa95532_0
terminado                 0.17.1          py311haa95532_0
threadpoolctl             2.2.0              pyh0d69192_0
tiledb                    2.13.2               h3132609_0    conda-forge
tinycss2                  1.2.1           py311haa95532_0
tk                        8.6.14               h0416ee5_0
toml                      0.10.2             pyhd3eb1b0_0
toolz                     0.12.0          py311haa95532_0
tornado                   6.4.1           py311h827c3e9_0
traitlets                 5.14.3          py311haa95532_0
traittypes                0.2.1              pyh9f0ad1d_2    conda-forge
typing-extensions         4.11.0          py311haa95532_0
typing_extensions         4.11.0          py311haa95532_0
tzdata                    2024a                h04d1e81_0
uc-micro-py               1.0.1           py311haa95532_0
ucrt                      10.0.22621.0         h57928b3_0    conda-forge
unicodedata2              15.1.0          py311h2bbff1b_0
uriparser                 0.9.7                h2bbff1b_0
urllib3                   2.2.2           py311haa95532_0
utf8proc                  2.6.1                h2bbff1b_1
uvicorn                   0.20.0          py311haa95532_0
vc                        14.2                 h2eaa2aa_1
vc14_runtime              14.40.33810         ha82c5b3_20    conda-forge
vs2015_runtime            14.40.33810         h3bf8584_20    conda-forge
watchdog                  4.0.1           py311haa95532_0
watchfiles                0.22.0          py311h533ab2d_0    conda-forge
wcwidth                   0.2.5              pyhd3eb1b0_0
webencodings              0.5.1           py311haa95532_1
websocket-client          1.8.0           py311haa95532_0
websockets                10.4            py311h2bbff1b_1
wheel                     0.43.0          py311haa95532_0
widgetsnbextension        3.6.6           py311haa95532_0
win_inet_pton             1.1.0           py311haa95532_0
winpty                    0.4.3                         4
xerces-c                  3.2.4                hd77b12b_1
xyzservices               2022.9.0        py311haa95532_1
xz                        5.4.6                h8cc25b3_1
yaml                      0.2.5                he774522_0
zeromq                    4.3.5                hd77b12b_0
zlib                      1.2.13               h2466b09_6    conda-forge
zstd                      1.5.5                hd43e919_2

@theroggy
Copy link
Member

There is quite some mixing of channels in the environment: many packages originate from the "defaults" channel, some are coming from "conda-forge", which introduces some risks in getting weird behaviour. In general it is recommended to (try to) avoid installing packages from different channels by creating your environment like this: creating-a-new-environment.

Nonetheless, you could try to solve it in your existing environment by upgrading pyogrio. As Brendan mentioned Writing to BytesIO was added in pyogrio 0.8.0... so you could try activating the environment and then running conda update "pyogrio>=0.8".

@fgashakamba
Copy link

I updated pyogrio to version 0.9.0 and then re-run the script again.
Now the error I am getting is:

 Exception in ASGI application
ImportError: DLL load failed while importing pyexpat: The operating system cannot run %1.

I guess it's not an issue with pyogrio any longer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants