Skip to content

Commit 79c6286

Browse files
committed
fix warnings and mypy errors
1 parent 98c5894 commit 79c6286

File tree

4 files changed

+139
-79
lines changed

4 files changed

+139
-79
lines changed

bigframes/core/compile/scalar_op_compiler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,11 +2164,11 @@ def st_boundary(a: ibis_dtypes.geography) -> ibis_dtypes.geography: # type: ign
21642164

21652165
@ibis_udf.scalar.builtin
21662166
def st_buffer(
2167-
geography: ibis_dtypes.Geography,
2167+
geography: ibis_dtypes.geography, # type: ignore
21682168
buffer_radius: ibis_dtypes.Float64,
21692169
num_seg_quarter_circle: ibis_dtypes.Float64,
21702170
use_spheroid: ibis_dtypes.Boolean,
2171-
) -> ibis_dtypes.Geography:
2171+
) -> ibis_dtypes.geography: # type: ignore
21722172
...
21732173

21742174

bigframes/geopandas/geoseries.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
# limitations under the License.
1414
from __future__ import annotations
1515

16+
from typing import Optional
17+
1618
import bigframes_vendored.constants as constants
1719
import bigframes_vendored.geopandas.geoseries as vendored_geoseries
1820
import geopandas.array # type: ignore
1921

20-
import bigframes.geopandas
2122
import bigframes.operations as ops
2223
import bigframes.series
24+
import bigframes.session
2325

2426

2527
class GeoSeries(vendored_geoseries.GeoSeries, bigframes.series.Series):
@@ -73,8 +75,14 @@ def is_closed(self) -> bigframes.series.Series:
7375
)
7476

7577
@classmethod
76-
def from_wkt(cls, data, index=None) -> GeoSeries:
77-
series = bigframes.series.Series(data, index=index)
78+
def from_wkt(
79+
cls,
80+
data,
81+
index=None,
82+
*,
83+
session: Optional[bigframes.session.Session] = None,
84+
) -> GeoSeries:
85+
series = bigframes.series.Series(data, index=index, session=session)
7886

7987
return cls(series._apply_unary_op(ops.geo_st_geogfromtext_op))
8088

@@ -97,9 +105,11 @@ def buffer(self: GeoSeries, distance: float) -> bigframes.series.Series: # type
97105
f"GeoSeries.buffer is not supported. Use bigframes.bigquery.st_buffer(series, distance), instead. {constants.FEEDBACK_LINK}"
98106
)
99107

108+
@property
100109
def centroid(self: GeoSeries) -> bigframes.series.Series: # type: ignore
101110
return self._apply_unary_op(ops.geo_st_centroid_op)
102111

112+
@property
103113
def convex_hull(self: GeoSeries) -> bigframes.series.Series: # type: ignore
104114
return self._apply_unary_op(ops.geo_st_convexhull_op)
105115

tests/system/small/bigquery/test_geo.py

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from __future__ import annotations
16+
1517
import geopandas # type: ignore
1618
import pandas as pd
1719
import pandas.testing
@@ -29,9 +31,10 @@
2931
from bigframes.bigquery import st_length
3032
import bigframes.bigquery as bbq
3133
import bigframes.geopandas
34+
import bigframes.session
3235

3336

34-
def test_geo_st_area():
37+
def test_geo_st_area(session: bigframes.session.Session):
3538
data = [
3639
Polygon([(0.000, 0.0), (0.001, 0.001), (0.000, 0.001)]),
3740
Polygon([(0.0010, 0.004), (0.009, 0.005), (0.0010, 0.005)]),
@@ -41,7 +44,7 @@ def test_geo_st_area():
4144
]
4245

4346
geopd_s = geopandas.GeoSeries(data=data, crs="EPSG:4326")
44-
geobf_s = bigframes.geopandas.GeoSeries(data=data)
47+
geobf_s = bigframes.geopandas.GeoSeries(data=data, session=session)
4548

4649
# For `geopd_s`, the data was further projected with `geopandas.GeoSeries.to_crs`
4750
# to `to_crs(26393)` to get the area in square meter. See: https://geopandas.org/en/stable/docs/user_guide/projections.html
@@ -123,7 +126,7 @@ def test_st_length_various_geometries(session):
123126
) # type: ignore
124127

125128

126-
def test_geo_st_difference_with_geometry_objects():
129+
def test_geo_st_difference_with_geometry_objects(session: bigframes.session.Session):
127130
data1 = [
128131
Polygon([(0, 0), (10, 0), (10, 10), (0, 0)]),
129132
Polygon([(0, 0), (1, 1), (0, 1), (0, 0)]),
@@ -136,8 +139,8 @@ def test_geo_st_difference_with_geometry_objects():
136139
LineString([(2, 0), (0, 2)]),
137140
]
138141

139-
geobf_s1 = bigframes.geopandas.GeoSeries(data=data1)
140-
geobf_s2 = bigframes.geopandas.GeoSeries(data=data2)
142+
geobf_s1 = bigframes.geopandas.GeoSeries(data=data1, session=session)
143+
geobf_s2 = bigframes.geopandas.GeoSeries(data=data2, session=session)
141144
geobf_s_result = bbq.st_difference(geobf_s1, geobf_s2).to_pandas()
142145

143146
expected = pd.Series(
@@ -158,7 +161,9 @@ def test_geo_st_difference_with_geometry_objects():
158161
)
159162

160163

161-
def test_geo_st_difference_with_single_geometry_object():
164+
def test_geo_st_difference_with_single_geometry_object(
165+
session: bigframes.session.Session,
166+
):
162167
pytest.importorskip(
163168
"shapely",
164169
minversion="2.0.0",
@@ -171,7 +176,7 @@ def test_geo_st_difference_with_single_geometry_object():
171176
Point(0, 1),
172177
]
173178

174-
geobf_s1 = bigframes.geopandas.GeoSeries(data=data1)
179+
geobf_s1 = bigframes.geopandas.GeoSeries(data=data1, session=session)
175180
geobf_s_result = bbq.st_difference(
176181
geobf_s1,
177182
Polygon([(0, 0), (10, 0), (10, 5), (0, 5), (0, 0)]),
@@ -195,14 +200,16 @@ def test_geo_st_difference_with_single_geometry_object():
195200
)
196201

197202

198-
def test_geo_st_difference_with_similar_geometry_objects():
203+
def test_geo_st_difference_with_similar_geometry_objects(
204+
session: bigframes.session.Session,
205+
):
199206
data1 = [
200207
Polygon([(0, 0), (10, 0), (10, 10), (0, 0)]),
201208
Polygon([(0, 0), (1, 1), (0, 1)]),
202209
Point(0, 1),
203210
]
204211

205-
geobf_s1 = bigframes.geopandas.GeoSeries(data=data1)
212+
geobf_s1 = bigframes.geopandas.GeoSeries(data=data1, session=session)
206213
geobf_s_result = bbq.st_difference(geobf_s1, geobf_s1).to_pandas()
207214

208215
expected = pd.Series(
@@ -219,7 +226,7 @@ def test_geo_st_difference_with_similar_geometry_objects():
219226
)
220227

221228

222-
def test_geo_st_distance_with_geometry_objects():
229+
def test_geo_st_distance_with_geometry_objects(session: bigframes.session.Session):
223230
data1 = [
224231
# 0.00001 is approximately 1 meter.
225232
Polygon([(0, 0), (0.00001, 0), (0.00001, 0.00001), (0, 0.00001), (0, 0)]),
@@ -252,8 +259,8 @@ def test_geo_st_distance_with_geometry_objects():
252259
), # No matching row in data1, so this will be NULL after the call to distance.
253260
]
254261

255-
geobf_s1 = bigframes.geopandas.GeoSeries(data=data1)
256-
geobf_s2 = bigframes.geopandas.GeoSeries(data=data2)
262+
geobf_s1 = bigframes.geopandas.GeoSeries(data=data1, session=session)
263+
geobf_s2 = bigframes.geopandas.GeoSeries(data=data2, session=session)
257264
geobf_s_result = bbq.st_distance(geobf_s1, geobf_s2).to_pandas()
258265

259266
expected = pd.Series(
@@ -275,7 +282,9 @@ def test_geo_st_distance_with_geometry_objects():
275282
)
276283

277284

278-
def test_geo_st_distance_with_single_geometry_object():
285+
def test_geo_st_distance_with_single_geometry_object(
286+
session: bigframes.session.Session,
287+
):
279288
pytest.importorskip(
280289
"shapely",
281290
minversion="2.0.0",
@@ -297,7 +306,7 @@ def test_geo_st_distance_with_single_geometry_object():
297306
Point(0, 0.00002),
298307
]
299308

300-
geobf_s1 = bigframes.geopandas.GeoSeries(data=data1)
309+
geobf_s1 = bigframes.geopandas.GeoSeries(data=data1, session=session)
301310
geobf_s_result = bbq.st_distance(
302311
geobf_s1,
303312
Point(0, 0),
@@ -320,7 +329,7 @@ def test_geo_st_distance_with_single_geometry_object():
320329
)
321330

322331

323-
def test_geo_st_intersection_with_geometry_objects():
332+
def test_geo_st_intersection_with_geometry_objects(session: bigframes.session.Session):
324333
data1 = [
325334
Polygon([(0, 0), (10, 0), (10, 10), (0, 0)]),
326335
Polygon([(0, 0), (1, 1), (0, 1), (0, 0)]),
@@ -333,8 +342,8 @@ def test_geo_st_intersection_with_geometry_objects():
333342
LineString([(2, 0), (0, 2)]),
334343
]
335344

336-
geobf_s1 = bigframes.geopandas.GeoSeries(data=data1)
337-
geobf_s2 = bigframes.geopandas.GeoSeries(data=data2)
345+
geobf_s1 = bigframes.geopandas.GeoSeries(data=data1, session=session)
346+
geobf_s2 = bigframes.geopandas.GeoSeries(data=data2, session=session)
338347
geobf_s_result = bbq.st_intersection(geobf_s1, geobf_s2).to_pandas()
339348

340349
expected = pd.Series(
@@ -355,7 +364,9 @@ def test_geo_st_intersection_with_geometry_objects():
355364
)
356365

357366

358-
def test_geo_st_intersection_with_single_geometry_object():
367+
def test_geo_st_intersection_with_single_geometry_object(
368+
session: bigframes.session.Session,
369+
):
359370
pytest.importorskip(
360371
"shapely",
361372
minversion="2.0.0",
@@ -368,7 +379,7 @@ def test_geo_st_intersection_with_single_geometry_object():
368379
Point(0, 1),
369380
]
370381

371-
geobf_s1 = bigframes.geopandas.GeoSeries(data=data1)
382+
geobf_s1 = bigframes.geopandas.GeoSeries(data=data1, session=session)
372383
geobf_s_result = bbq.st_intersection(
373384
geobf_s1,
374385
Polygon([(0, 0), (10, 0), (10, 5), (0, 5), (0, 0)]),
@@ -392,14 +403,16 @@ def test_geo_st_intersection_with_single_geometry_object():
392403
)
393404

394405

395-
def test_geo_st_intersection_with_similar_geometry_objects():
406+
def test_geo_st_intersection_with_similar_geometry_objects(
407+
session: bigframes.session.Session,
408+
):
396409
data1 = [
397410
Polygon([(0, 0), (10, 0), (10, 10), (0, 0)]),
398411
Polygon([(0, 0), (1, 1), (0, 1)]),
399412
Point(0, 1),
400413
]
401414

402-
geobf_s1 = bigframes.geopandas.GeoSeries(data=data1)
415+
geobf_s1 = bigframes.geopandas.GeoSeries(data=data1, session=session)
403416
geobf_s_result = bbq.st_intersection(geobf_s1, geobf_s1).to_pandas()
404417

405418
expected = pd.Series(
@@ -420,20 +433,23 @@ def test_geo_st_intersection_with_similar_geometry_objects():
420433
)
421434

422435

423-
def test_geo_st_isclosed():
436+
def test_geo_st_isclosed(session: bigframes.session.Session):
424437
bf_gs = bigframes.geopandas.GeoSeries(
425438
[
426439
Point(0, 0), # Point
427440
LineString([(0, 0), (1, 1)]), # Open LineString
428441
LineString([(0, 0), (1, 1), (0, 1), (0, 0)]), # Closed LineString
429442
Polygon([(0, 0), (1, 1), (0, 1)]), # Open polygon
430443
GeometryCollection(), # Empty GeometryCollection
431-
bigframes.geopandas.GeoSeries.from_wkt(["GEOMETRYCOLLECTION EMPTY"]).iloc[
444+
bigframes.geopandas.GeoSeries.from_wkt(
445+
["GEOMETRYCOLLECTION EMPTY"], session=session
446+
).iloc[
432447
0
433448
], # Also empty
434449
None, # Should be filtered out by dropna
435450
],
436451
index=[0, 1, 2, 3, 4, 5, 6],
452+
session=session,
437453
)
438454
bf_result = bbq.st_isclosed(bf_gs).to_pandas()
439455

0 commit comments

Comments
 (0)