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

PERF: improve reading of geoarrow encoded Parquet (avoid converting coords to geopandas object dtype) #3322

Conversation

jorisvandenbossche
Copy link
Member

This reduces the time to read a simple geoparquet file with 10 million points from about 6 seconds to about 3 seconds.
Surprisingly, this also reduces the time in the case of reading such a file with the default WKB encoding, because for some reason the conversion in pyarrow for variable size binary column to numpy is faster than to pandas (which doesn't really make sense since both create the same object dtype array, will have to investigate and report upstream to pyarrow)

This takes a similar approach as the GeoArrow import code (#3301), i.e. only converting the attributes from Arrow -> Pandas, and then separately the geometry columns. In case of geoarrow-encoded columns, this avoids converting the nested struct to python lists/dictionaries (which we then don't use anyway, because we create the geometries directly from the raw Arrow data).
It is a bit unfortunate that this logic is a bit duplicated between arrow.py and geoarrow.py. But the problem is that for from_arrow the logic is based on checking the arrow extension metadata, while for GeoParquet we need to support generic files that might not have that Arrow-specific metadata.

N = 10_000_000

df = geopandas.GeoDataFrame({"col": range(N)}, geometry=geopandas.GeoSeries.from_xy(np.random.rand(N), np.random.rand(N)))
df.to_parquet("/tmp/test_points_wkb.parquet", geometry_encoding="WKB")
df.to_parquet("/tmp/test_points_geoarrow.parquet", geometry_encoding="geoarrow")
In [11]: %time geopandas.read_parquet("/tmp/test_points_wkb.parquet")
CPU times: user 5.22 s, sys: 1.7 s, total: 6.91 s
Wall time: 6.54 s  # <-- main
Wall time: 4.09 s  # <-- PR

In [12]: %time geopandas.read_parquet("/tmp/test_points_geoarrow.parquet")
CPU times: user 4.92 s, sys: 1.71 s, total: 6.62 s
Wall time: 6.4 s  # <-- main
Wall time: 3.65 s  # <-- PR

(it's also a bit disappointing how creating Points from x/y values is only slightly faster than parsing WKB, but that's something to profile on the shapely side)

Copy link
Member

@martinfleis martinfleis left a comment

Choose a reason for hiding this comment

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

Interesting...

Copy link
Member

@m-richards m-richards left a comment

Choose a reason for hiding this comment

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

Thanks Joris!

@jorisvandenbossche
Copy link
Member Author

Opened apache/arrow#42026 for the pyarrow perf issue

@jorisvandenbossche jorisvandenbossche merged commit a61af6e into geopandas:main Jun 7, 2024
20 checks passed
@jorisvandenbossche jorisvandenbossche deleted the perf-read-parquet-geoarrow branch June 7, 2024 09:12
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.

None yet

3 participants