Skip to content

Commit 3759c63

Browse files
rey-esparwas11
andauthored
feat: add basic geopandas functionality (#962)
* feat: add basic geopandas functionality * update examples for geoseries * feat: add Series.geo helper to convert Series to a GeoSeries * fix cirucular import * Added a constructor * add documentation for geoseries * remove GeoSeries.x and GeoSeries.y temporarily --------- Co-authored-by: Arwa <[email protected]>
1 parent 72c228b commit 3759c63

File tree

8 files changed

+146
-2
lines changed

8 files changed

+146
-2
lines changed

bigframes/geopandas/__init__.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2023 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+
from bigframes.geopandas.geoseries import GeoSeries
16+
17+
__all__ = ["GeoSeries"]

bigframes/geopandas/geoseries.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
from __future__ import annotations
15+
16+
import bigframes_vendored.geopandas.geoseries as vendored_geoseries
17+
import geopandas.array # type: ignore
18+
19+
import bigframes.series
20+
21+
22+
class GeoSeries(vendored_geoseries.GeoSeries, bigframes.series.Series):
23+
__doc__ = vendored_geoseries.GeoSeries.__doc__
24+
25+
def __init__(self, data=None, index=None, **kwargs):
26+
super().__init__(
27+
data=data, index=index, dtype=geopandas.array.GeometryDtype(), **kwargs
28+
)

bigframes/series.py

+17
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
import bigframes.operations.strings as strings
6161
import bigframes.operations.structs as structs
6262

63+
if typing.TYPE_CHECKING:
64+
import bigframes.geopandas.geoseries
65+
6366
LevelType = typing.Union[str, int]
6467
LevelsType = typing.Union[LevelType, typing.Sequence[LevelType]]
6568

@@ -91,6 +94,20 @@ def dtype(self):
9194
def dtypes(self):
9295
return self._dtype
9396

97+
@property
98+
def geo(self) -> bigframes.geopandas.geoseries.GeoSeries:
99+
"""
100+
Accessor object for geography properties of the Series values.
101+
102+
Returns:
103+
bigframes.geopandas.geoseries.GeoSeries:
104+
An accessor containing geography methods.
105+
106+
"""
107+
import bigframes.geopandas.geoseries
108+
109+
return bigframes.geopandas.geoseries.GeoSeries(self)
110+
94111
@property
95112
@validations.requires_index
96113
def loc(self) -> bigframes.core.indexers.LocSeriesIndexer:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
=========
3+
GeoSeries
4+
=========
5+
6+
.. contents:: Table of Contents
7+
:depth: 2
8+
:local:
9+
:backlinks: none
10+
11+
Series
12+
------
13+
14+
.. autoclass:: bigframes.geopandas.geoseries.GeoSeries
15+
:members:
16+
:inherited-members:
17+
:undoc-members:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
===============================
3+
BigQuery DataFrames (geopandas)
4+
===============================
5+
6+
.. toctree::
7+
:maxdepth: 2
8+
9+
geoseries

docs/reference/index.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ packages.
88
:maxdepth: 2
99

1010
bigframes/index
11-
bigframes.pandas/index
12-
bigframes.ml/index
1311
bigframes.bigquery/index
12+
bigframes.geopandas/index
13+
bigframes.ml/index
14+
bigframes.pandas/index
1415
bigframes.streaming/index
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Copyright (c) 2013-2022, GeoPandas developers.
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above copyright notice,
10+
this list of conditions and the following disclaimer in the documentation
11+
and/or other materials provided with the distribution.
12+
* Neither the name of GeoPandas nor the names of its contributors may
13+
be used to endorse or promote products derived from this software without
14+
specific prior written permission.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# contains code from https://github.com/geopandas/geopandas/blob/main/geopandas/geoseries.py
2+
from __future__ import annotations
3+
4+
5+
class GeoSeries:
6+
"""
7+
A Series object designed to store geometry objects.
8+
9+
**Examples:**
10+
11+
>>> import bigframes.geopandas
12+
>>> import bigframes.pandas as bpd
13+
>>> bpd.options.display.progress_bar = None
14+
>>> from shapely.geometry import Point
15+
>>> s = bigframes.geopandas.GeoSeries([Point(1, 1), Point(2, 2), Point(3, 3)])
16+
>>> s
17+
0 POINT (1 1)
18+
1 POINT (2 2)
19+
2 POINT (3 3)
20+
dtype: geometry
21+
22+
Args:
23+
data (array-like, dict, scalar value, bigframes.pandas.Series):
24+
The geometries to store in the GeoSeries.
25+
index (array-like, pandas.Index, bigframes.pandas.Index):
26+
The index for the GeoSeries.
27+
kwargs (dict):
28+
Additional arguments passed to the Series constructor,
29+
e.g. ``name``.
30+
"""

0 commit comments

Comments
 (0)