Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add basic geopandas functionality #962

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions bigframes/geopandas/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from bigframes.geopandas.geoseries import GeoSeries

__all__ = ["GeoSeries"]
26 changes: 26 additions & 0 deletions bigframes/geopandas/geoseries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations

import bigframes_vendored.geopandas.geoseries as vendored_geoseries
import geopandas.array

import bigframes.series


class GeoSeries(vendored_geoseries.GeoSeries, bigframes.series.Series):
def __init__(self, data=None, index=None, **kwargs):
super().__init__(
data=data, index=index, dtype=geopandas.array.GeometryDtype(), **kwargs
)
17 changes: 17 additions & 0 deletions bigframes/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
import bigframes.operations.strings as strings
import bigframes.operations.structs as structs

if typing.TYPE_CHECKING:
import bigframes.geopandas.geoseries

LevelType = typing.Union[str, int]
LevelsType = typing.Union[LevelType, typing.Sequence[LevelType]]

Expand Down Expand Up @@ -89,6 +92,20 @@ def dtype(self):
def dtypes(self):
return self._dtype

@property
def geo(self) -> bigframes.geopandas.geoseries.GeoSeries:
"""
Accessor object for geography properties of the Series values.

Returns:
bigframes.geopandas.geoseries.GeoSeries:
An accessor containing geography methods.

"""
import bigframes.geopandas.geoseries

return bigframes.geopandas.geoseries.GeoSeries(self)

@property
@validations.requires_index
def loc(self) -> bigframes.core.indexers.LocSeriesIndexer:
Expand Down
25 changes: 25 additions & 0 deletions third_party/bigframes_vendored/geopandas/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Copyright (c) 2013-2022, GeoPandas developers.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of GeoPandas nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
69 changes: 69 additions & 0 deletions third_party/bigframes_vendored/geopandas/geoseries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# contains code from https://github.com/geopandas/geopandas/blob/main/geopandas/geoseries.py
from __future__ import annotations

from typing import TYPE_CHECKING

from bigframes import constants

if TYPE_CHECKING:
import bigframes.series


class GeoSeries:
"""
A Series object designed to store geometry objects.
"""

@property
def x(self) -> bigframes.series.Series:
"""Return the x location of point geometries in a GeoSeries

**Examples:**

>>> import bigframes.pandas as bpd
>>> bpd.options.display.progress_bar = None
>>> import geopandas.array
>>> import shapely

>>> series = bpd.Series(
... [shapely.Point(1, 1), shapely.Point(2, 2), shapely.Point(3, 3)],
... dtype=geopandas.array.GeometryDtype()
... )
>>> series.geo.x
0 1.0
1 2.0
2 3.0
dtype: float64

Returns:
bigframes.series.Series:
Return the x location (longitude) of point geometries.
"""
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)

@property
def y(self) -> bigframes.series.Series:
"""Return the y location of point geometries in a GeoSeries

**Examples:**

>>> import bigframes.pandas as bpd
>>> bpd.options.display.progress_bar = None
>>> import geopandas.array
>>> import shapely

>>> series = bpd.Series(
... [shapely.Point(1, 1), shapely.Point(2, 2), shapely.Point(3, 3)],
... dtype=geopandas.array.GeometryDtype()
... )
>>> series.geo.y
0 1.0
1 2.0
2 3.0
dtype: float64

Returns:
bigframes.series.Series:
Return the y location (latitude) of point geometries.
"""
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)