|
| 1 | +# Copyright 2024 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import geopandas # type: ignore |
| 16 | +import google.api_core.exceptions |
| 17 | +import pandas as pd |
| 18 | +import pytest |
| 19 | + |
| 20 | +import bigframes.geopandas |
| 21 | +import bigframes.series |
| 22 | +from tests.system.utils import assert_series_equal |
| 23 | + |
| 24 | + |
| 25 | +@pytest.fixture(scope="session") |
| 26 | +def urban_areas_dfs(session, urban_areas_table_id): |
| 27 | + bf_ua = session.read_gbq(urban_areas_table_id, index_col="geo_id") |
| 28 | + pd_ua = bf_ua.to_pandas() |
| 29 | + return (bf_ua, pd_ua) |
| 30 | + |
| 31 | + |
| 32 | +def test_geo_x(urban_areas_dfs): |
| 33 | + bf_ua, pd_ua = urban_areas_dfs |
| 34 | + bf_series: bigframes.geopandas.GeoSeries = bf_ua["internal_point_geom"].geo |
| 35 | + pd_series: geopandas.GeoSeries = geopandas.GeoSeries(pd_ua["internal_point_geom"]) |
| 36 | + bf_result = bf_series.x.to_pandas() |
| 37 | + pd_result = pd_series.x |
| 38 | + |
| 39 | + assert_series_equal( |
| 40 | + pd_result.astype(pd.Float64Dtype()), |
| 41 | + bf_result, |
| 42 | + ) |
| 43 | + |
| 44 | + |
| 45 | +def test_geo_x_non_point(urban_areas_dfs): |
| 46 | + bf_ua, _ = urban_areas_dfs |
| 47 | + bf_series: bigframes.geopandas.GeoSeries = bf_ua["urban_area_geom"].geo |
| 48 | + |
| 49 | + with pytest.raises(google.api_core.exceptions.BadRequest, match="ST_X"): |
| 50 | + bf_series.x.to_pandas() |
| 51 | + |
| 52 | + |
| 53 | +def test_geo_y(urban_areas_dfs): |
| 54 | + bf_ua, pd_ua = urban_areas_dfs |
| 55 | + bf_series: bigframes.geopandas.GeoSeries = bf_ua["internal_point_geom"].geo |
| 56 | + pd_series: geopandas.GeoSeries = geopandas.GeoSeries(pd_ua["internal_point_geom"]) |
| 57 | + bf_result = bf_series.y.to_pandas() |
| 58 | + pd_result = pd_series.y |
| 59 | + |
| 60 | + assert_series_equal( |
| 61 | + pd_result.astype(pd.Float64Dtype()), |
| 62 | + bf_result, |
| 63 | + ) |
0 commit comments