Skip to content

Commit ae83e61

Browse files
authored
deps: support shapely 1.8.5+ again (#1651)
1 parent 26ae5e7 commit ae83e61

File tree

7 files changed

+55
-26
lines changed

7 files changed

+55
-26
lines changed

bigframes/bigquery/_operations/geo.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ def st_area(
106106
def st_difference(
107107
series: Union[bigframes.series.Series, bigframes.geopandas.GeoSeries],
108108
other: Union[
109-
bigframes.series.Series, bigframes.geopandas.GeoSeries, shapely.Geometry
109+
bigframes.series.Series,
110+
bigframes.geopandas.GeoSeries,
111+
shapely.geometry.base.BaseGeometry,
110112
],
111113
) -> bigframes.series.Series:
112114
"""
@@ -207,7 +209,9 @@ def st_difference(
207209
def st_distance(
208210
series: Union[bigframes.series.Series, bigframes.geopandas.GeoSeries],
209211
other: Union[
210-
bigframes.series.Series, bigframes.geopandas.GeoSeries, shapely.Geometry
212+
bigframes.series.Series,
213+
bigframes.geopandas.GeoSeries,
214+
shapely.geometry.base.BaseGeometry,
211215
],
212216
*,
213217
use_spheroid: bool = False,
@@ -282,7 +286,9 @@ def st_distance(
282286
def st_intersection(
283287
series: Union[bigframes.series.Series, bigframes.geopandas.GeoSeries],
284288
other: Union[
285-
bigframes.series.Series, bigframes.geopandas.GeoSeries, shapely.Geometry
289+
bigframes.series.Series,
290+
bigframes.geopandas.GeoSeries,
291+
shapely.geometry.base.BaseGeometry,
286292
],
287293
) -> bigframes.series.Series:
288294
"""

bigframes/dtypes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ def _infer_dtype_from_python_type(type_: type) -> Dtype:
607607
return DATE_DTYPE
608608
if issubclass(type_, datetime.time):
609609
return TIME_DTYPE
610-
if issubclass(type_, shapely.Geometry):
610+
if issubclass(type_, shapely.geometry.base.BaseGeometry):
611611
return GEO_DTYPE
612612
else:
613613
raise TypeError(

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"pyarrow >=15.0.2",
5454
"pydata-google-auth >=1.8.2",
5555
"requests >=2.27.1",
56-
"shapely >=2.0.0",
56+
"shapely >=1.8.5",
5757
"sqlglot >=23.6.3",
5858
"tabulate >=0.9",
5959
"ipywidgets >=7.7.1",

testing/constraints-3.9.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pyarrow==15.0.2
1919
pydata-google-auth==1.8.2
2020
requests==2.27.1
2121
scikit-learn==1.2.2
22-
shapely==2.0.0
22+
shapely==1.8.5
2323
sqlglot==23.6.3
2424
tabulate==0.9
2525
ipywidgets==7.7.1

tests/system/small/bigquery/test_geo.py

+19
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import geopandas # type: ignore
1616
import pandas as pd
1717
import pandas.testing
18+
import pytest
1819
from shapely.geometry import ( # type: ignore
1920
GeometryCollection,
2021
LineString,
@@ -94,6 +95,12 @@ def test_geo_st_difference_with_geometry_objects():
9495

9596

9697
def test_geo_st_difference_with_single_geometry_object():
98+
pytest.importorskip(
99+
"shapely",
100+
minversion="2.0.0",
101+
reason="shapely objects must be hashable to include in our expression trees",
102+
)
103+
97104
data1 = [
98105
Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]),
99106
Polygon([(0, 1), (10, 1), (10, 9), (0, 9), (0, 1)]),
@@ -205,6 +212,12 @@ def test_geo_st_distance_with_geometry_objects():
205212

206213

207214
def test_geo_st_distance_with_single_geometry_object():
215+
pytest.importorskip(
216+
"shapely",
217+
minversion="2.0.0",
218+
reason="shapely objects must be hashable to include in our expression trees",
219+
)
220+
208221
data1 = [
209222
# 0.00001 is approximately 1 meter.
210223
Polygon([(0, 0), (0.00001, 0), (0.00001, 0.00001), (0, 0.00001), (0, 0)]),
@@ -279,6 +292,12 @@ def test_geo_st_intersection_with_geometry_objects():
279292

280293

281294
def test_geo_st_intersection_with_single_geometry_object():
295+
pytest.importorskip(
296+
"shapely",
297+
minversion="2.0.0",
298+
reason="shapely objects must be hashable to include in our expression trees",
299+
)
300+
282301
data1 = [
283302
Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]),
284303
Polygon([(0, 1), (10, 1), (10, 9), (0, 9), (0, 1)]),

tests/unit/core/test_dtypes.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import pandas as pd
2121
import pyarrow as pa # type: ignore
2222
import pytest
23-
import shapely # type: ignore
23+
import shapely.geometry # type: ignore
2424

2525
import bigframes.core.compile.ibis_types
2626
import bigframes.dtypes
@@ -231,9 +231,9 @@ def test_bigframes_string_dtype_converts(ibis_dtype, bigframes_dtype_str):
231231
(bool, bigframes.dtypes.BOOL_DTYPE),
232232
(int, bigframes.dtypes.INT_DTYPE),
233233
(str, bigframes.dtypes.STRING_DTYPE),
234-
(shapely.Point, bigframes.dtypes.GEO_DTYPE),
235-
(shapely.Polygon, bigframes.dtypes.GEO_DTYPE),
236-
(shapely.Geometry, bigframes.dtypes.GEO_DTYPE),
234+
(shapely.geometry.Point, bigframes.dtypes.GEO_DTYPE),
235+
(shapely.geometry.Polygon, bigframes.dtypes.GEO_DTYPE),
236+
(shapely.geometry.base.BaseGeometry, bigframes.dtypes.GEO_DTYPE),
237237
],
238238
)
239239
def test_bigframes_type_supports_python_types(python_type, expected_dtype):

tests/unit/core/test_sql.py

+20-16
Original file line numberDiff line numberDiff line change
@@ -74,43 +74,45 @@ def test_simple_literal(value, expected_pattern):
7474

7575

7676
@pytest.mark.parametrize(
77-
("value", "expected"),
77+
("value", "expected_pattern"),
7878
(
7979
# Try to have some list of literals for each scalar data type:
8080
# https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types
81-
([None, None], "[NULL, NULL]"),
82-
([True, False], "[True, False]"),
81+
([None, None], re.escape("[NULL, NULL]")),
82+
([True, False], re.escape("[True, False]")),
8383
(
8484
[b"\x01\x02\x03ABC", b"\x01\x02\x03ABC"],
85-
"[b'\\x01\\x02\\x03ABC', b'\\x01\\x02\\x03ABC']",
85+
re.escape("[b'\\x01\\x02\\x03ABC', b'\\x01\\x02\\x03ABC']"),
8686
),
8787
(
8888
[datetime.date(2025, 1, 1), datetime.date(2025, 1, 1)],
89-
"[DATE('2025-01-01'), DATE('2025-01-01')]",
89+
re.escape("[DATE('2025-01-01'), DATE('2025-01-01')]"),
9090
),
9191
(
9292
[datetime.datetime(2025, 1, 2, 3, 45, 6, 789123)],
93-
"[DATETIME('2025-01-02T03:45:06.789123')]",
93+
re.escape("[DATETIME('2025-01-02T03:45:06.789123')]"),
9494
),
9595
(
96-
[shapely.Point(0, 1), shapely.Point(0, 2)],
97-
"[ST_GEOGFROMTEXT('POINT (0 1)'), ST_GEOGFROMTEXT('POINT (0 2)')]",
96+
[shapely.geometry.Point(0, 1), shapely.geometry.Point(0, 2)],
97+
r"\[ST_GEOGFROMTEXT\('POINT \(0[.]?0* 1[.]?0*\)'\), ST_GEOGFROMTEXT\('POINT \(0[.]?0* 2[.]?0*\)'\)\]",
9898
),
9999
# TODO: INTERVAL type (e.g. from dateutil.relativedelta)
100100
# TODO: JSON type (TBD what Python object that would correspond to)
101-
([123, 456], "[123, 456]"),
101+
([123, 456], re.escape("[123, 456]")),
102102
(
103103
[decimal.Decimal("123.75"), decimal.Decimal("456.78")],
104-
"[CAST('123.75' AS NUMERIC), CAST('456.78' AS NUMERIC)]",
104+
re.escape("[CAST('123.75' AS NUMERIC), CAST('456.78' AS NUMERIC)]"),
105105
),
106106
# TODO: support BIGNUMERIC by looking at precision/scale of the DECIMAL
107-
([123.75, 456.78], "[123.75, 456.78]"),
107+
([123.75, 456.78], re.escape("[123.75, 456.78]")),
108108
# TODO: support RANGE type
109-
(["abc", "def"], "['abc', 'def']"),
109+
(["abc", "def"], re.escape("['abc', 'def']")),
110110
# TODO: support STRUCT type (possibly another method?)
111111
(
112112
[datetime.time(12, 34, 56, 789123), datetime.time(11, 25, 56, 789123)],
113-
"[TIME(DATETIME('1970-01-01 12:34:56.789123')), TIME(DATETIME('1970-01-01 11:25:56.789123'))]",
113+
re.escape(
114+
"[TIME(DATETIME('1970-01-01 12:34:56.789123')), TIME(DATETIME('1970-01-01 11:25:56.789123'))]"
115+
),
114116
),
115117
(
116118
[
@@ -121,13 +123,15 @@ def test_simple_literal(value, expected_pattern):
121123
2025, 2, 1, 4, 45, 6, 789123, tzinfo=datetime.timezone.utc
122124
),
123125
],
124-
"[TIMESTAMP('2025-01-02T03:45:06.789123+00:00'), TIMESTAMP('2025-02-01T04:45:06.789123+00:00')]",
126+
re.escape(
127+
"[TIMESTAMP('2025-01-02T03:45:06.789123+00:00'), TIMESTAMP('2025-02-01T04:45:06.789123+00:00')]"
128+
),
125129
),
126130
),
127131
)
128-
def test_simple_literal_w_list(value: list, expected: str):
132+
def test_simple_literal_w_list(value: list, expected_pattern: str):
129133
got = sql.simple_literal(value)
130-
assert got == expected
134+
assert re.match(expected_pattern, got) is not None
131135

132136

133137
def test_create_vector_search_sql_simple():

0 commit comments

Comments
 (0)