1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15+ from __future__ import annotations
16+
1517import geopandas # type: ignore
1618import pandas as pd
1719import pandas .testing
2931from bigframes .bigquery import st_length
3032import bigframes .bigquery as bbq
3133import 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