Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions python/sedona/spark/geopandas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5141,8 +5141,9 @@ def buffer(
mitre_limit : float, default 5.0
The mitre limit ratio for joins when join_style='mitre'.
single_sided : bool, default False
Whether to create a single-sided buffer. In Sedona, True will default to left-sided buffer.
However, 'right' may be specified to use a right-sided buffer.
Whether to create a single-sided buffer. As in GeoPandas, the sign of
``distance`` picks the side: a positive distance buffers the left side,
and a negative distance buffers the right side.
**kwargs
Accepted for compatibility with GeoPandas and ignored.

Expand Down
20 changes: 14 additions & 6 deletions python/sedona/spark/geopandas/geoseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -4478,9 +4478,9 @@ def from_wkb(
unclosed rings). If this is not possible, they are returned as ``None``
without a warning. Requires GEOS >= 3.11 and shapely >= 2.1.

kwargs
Additional arguments passed to the Series constructor,
e.g. ``name``.
**kwargs
Only ``name`` is supported, the name of the resulting GeoSeries.
Other keyword arguments raise ``TypeError``.

Returns
-------
Expand Down Expand Up @@ -4514,6 +4514,10 @@ def from_wkb(
2 POINT (3 3)
dtype: geometry
"""
unsupported = set(kwargs) - {"name"}
if unsupported:
arguments = ", ".join(sorted(unsupported))
raise TypeError(f"Unsupported GeoSeries.from_wkb arguments: {arguments}")
if on_invalid != "raise":
raise NotImplementedError(
"GeoSeries.from_wkb(): only on_invalid='raise' is implemented"
Expand Down Expand Up @@ -4566,9 +4570,9 @@ def from_wkt(
unclosed rings). If this is not possible, they are returned as ``None``
without a warning. Requires GEOS >= 3.11 and shapely >= 2.1.

kwargs
Additional arguments passed to the Series constructor,
e.g. ``name``.
**kwargs
Only ``name`` is supported, the name of the resulting GeoSeries.
Other keyword arguments raise ``TypeError``.

Returns
-------
Expand All @@ -4594,6 +4598,10 @@ def from_wkt(
2 POINT (3 3)
dtype: geometry
"""
unsupported = set(kwargs) - {"name"}
if unsupported:
arguments = ", ".join(sorted(unsupported))
raise TypeError(f"Unsupported GeoSeries.from_wkt arguments: {arguments}")
if on_invalid != "raise":
raise NotImplementedError(
"GeoSeries.from_wkt(): only on_invalid='raise' is implemented"
Expand Down
13 changes: 7 additions & 6 deletions python/sedona/spark/geopandas/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,19 @@ def read_file(filename: str, format: Union[str, None] = None, **kwargs):
- "geoparquet"
**kwargs
Reader options. Only ``table_name`` is used: the name of the table to
read, required when ``format`` is "geopackage". Sedona warns about the
keyword arguments it receives, since other GeoPandas reader options are
not supported.
read, required when ``format`` is "geopackage". Sedona warns about any
other keyword argument, since other GeoPandas reader options are not
supported.

See also
--------
GeoDataFrame.to_file : write GeoDataFrame to file
"""

# We warn the user if they try to use arguments that GeoPandas supports but not Sedona.
if kwargs:
warnings.warn(f"The given arguments are not supported in Sedona: {kwargs}")
unsupported = {k: v for k, v in kwargs.items() if k != "table_name"}
if unsupported:
warnings.warn(f"The given arguments are not supported in Sedona: {unsupported}")

spark = default_session()

Expand Down Expand Up @@ -392,4 +393,4 @@ def read_parquet(
if kwargs:
warnings.warn(f"The given arguments are not supported in Sedona: {kwargs}")

return read_file(path, format="geoparquet", **kwargs)
return read_file(path, format="geoparquet")
15 changes: 15 additions & 0 deletions python/tests/geopandas/test_geoseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,21 @@ def test_from_wkt(self):
expected = gpd.GeoSeries([Point(1, 1), Point(2, 2), Point(3, 3)])
self.check_sgpd_equals_gpd(s, expected)

@pytest.mark.parametrize(
"constructor,value",
[
(GeoSeries.from_wkt, "POINT (1 1)"),
(GeoSeries.from_wkb, Point(1, 1).wkb),
],
ids=["wkt", "wkb"],
)
def test_wkt_wkb_keyword_arguments(self, constructor, value):
assert constructor([value], name="geom").name == "geom"
with pytest.raises(
TypeError, match="Unsupported GeoSeries.from_wk[tb] arguments: dtype"
):
constructor([value], dtype="geometry")

@pytest.mark.parametrize(
"constructor,value",
[
Expand Down
15 changes: 15 additions & 0 deletions python/tests/geopandas/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import os
import sqlite3
import tempfile
import warnings
import pytest
import shapely
import pandas as pd
Expand Down Expand Up @@ -359,6 +360,20 @@ def test_read_geopackage(self, read_func):
assert df.active_geometry_name == "geom"
assert df["geom"].count() == expected_cnt

def test_read_file_warns_only_about_unsupported_arguments(self):
datafile = os.path.join(TEST_DATA_DIR, "geopackage/features.gpkg")
table_name = "GB_Hex_5km_GS_Landslides_v8"

with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter("always")
read_file(datafile, table_name=table_name)
assert not [w for w in caught if "not supported in Sedona" in str(w.message)]

with pytest.warns(UserWarning, match="not supported in Sedona") as caught:
read_file(datafile, table_name=table_name, rows=10)
messages = [str(w.message) for w in caught]
assert any("rows" in m and "table_name" not in m for m in messages)

def test_geoseries_from_geopackage_uses_source_geometry_name(self):
datafile = os.path.join(TEST_DATA_DIR, "geopackage/features.gpkg")

Expand Down
5 changes: 5 additions & 0 deletions python/tests/geopandas/test_match_geopandas_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ def test_buffer(self):
gpd_result = gpd.GeoSeries(self.linestrings).buffer(0.2, single_sided=True)
self.check_sgpd_equals_gpd(sgpd_result, gpd_result)

# A negative distance buffers the right side.
sgpd_result = GeoSeries(self.linestrings).buffer(-0.2, single_sided=True)
gpd_result = gpd.GeoSeries(self.linestrings).buffer(-0.2, single_sided=True)
self.check_sgpd_equals_gpd(sgpd_result, gpd_result)

sgpd_result = GeoSeries(self.linestrings).buffer(
0.2, join_style="mitre", mitre_limit=10.0
)
Expand Down
Loading