From 0538168001c1a5455655e6dcee526b6d32342296 Mon Sep 17 00:00:00 2001 From: Arwa Date: Tue, 1 Oct 2024 16:17:28 -0500 Subject: [PATCH 1/3] feat: support uploading local geo data --- bigframes/session/__init__.py | 6 ++---- tests/system/small/test_series.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/bigframes/session/__init__.py b/bigframes/session/__init__.py index 0d7a90c250..349885dff0 100644 --- a/bigframes/session/__init__.py +++ b/bigframes/session/__init__.py @@ -703,10 +703,8 @@ def _read_pandas_inline( try: local_block = blocks.Block.from_local(pandas_dataframe, self) inline_df = dataframe.DataFrame(local_block) - except pa.ArrowInvalid as e: - raise pa.ArrowInvalid( - f"Could not convert with a BigQuery type: `{e}`. " - ) from e + except pa.ArrowInvalid: + return None except ValueError: # Thrown by ibis for some unhandled types return None except pa.ArrowTypeError: # Thrown by arrow for types without mapping (geo). diff --git a/tests/system/small/test_series.py b/tests/system/small/test_series.py index 624e287f8d..94a9b132bb 100644 --- a/tests/system/small/test_series.py +++ b/tests/system/small/test_series.py @@ -23,6 +23,7 @@ import pandas as pd import pyarrow as pa # type: ignore import pytest +import shapely import bigframes.pandas import bigframes.series as series @@ -213,6 +214,19 @@ def test_series_construct_from_list_escaped_strings(): pd.testing.assert_series_equal(bf_result.to_pandas(), pd_result) +def test_series_construct_geodata(): + pd_series = pd.Series( + [shapely.Point(1, 1), shapely.Point(2, 2), shapely.Point(3, 3)], + dtype=gpd.array.GeometryDtype(), + ) + + series = bigframes.pandas.Series(pd_series) + + pd.testing.assert_series_equal( + pd_series, series.to_pandas(), check_index_type=False + ) + + @pytest.mark.parametrize( ["col_name", "expected_dtype"], [ From f93444d7cffea22c093fcf3a1501ba79b5c4fd93 Mon Sep 17 00:00:00 2001 From: Arwa Date: Wed, 2 Oct 2024 10:52:21 -0500 Subject: [PATCH 2/3] Fix mypy error --- tests/system/small/test_series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system/small/test_series.py b/tests/system/small/test_series.py index 94a9b132bb..ddfed6ec4e 100644 --- a/tests/system/small/test_series.py +++ b/tests/system/small/test_series.py @@ -23,7 +23,7 @@ import pandas as pd import pyarrow as pa # type: ignore import pytest -import shapely +import shapely # type: ignore import bigframes.pandas import bigframes.series as series From a71e5322584542551cac20bf59021cd37091bef2 Mon Sep 17 00:00:00 2001 From: Arwa Date: Wed, 2 Oct 2024 13:17:42 -0500 Subject: [PATCH 3/3] Add explanatory comment --- bigframes/session/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bigframes/session/__init__.py b/bigframes/session/__init__.py index 349885dff0..1135445cd6 100644 --- a/bigframes/session/__init__.py +++ b/bigframes/session/__init__.py @@ -703,7 +703,7 @@ def _read_pandas_inline( try: local_block = blocks.Block.from_local(pandas_dataframe, self) inline_df = dataframe.DataFrame(local_block) - except pa.ArrowInvalid: + except pa.ArrowInvalid: # Thrown by arrow for unsupported types, such as geo. return None except ValueError: # Thrown by ibis for some unhandled types return None