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 geo accessor to Series #644

Closed
wants to merge 2 commits into from
Closed
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
25 changes: 25 additions & 0 deletions bigframes/geopandas/LICENSE.txt
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in third_party.

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.
21 changes: 21 additions & 0 deletions bigframes/geopandas/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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.

import geopandas as gpd


class GeoSeries(gpd.GeoSeries):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of subclassing geopandas.GeoSeries, subclass your new third_party version of it.

def distance(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed in chat, let's do x and y properties to start to avoid complexities with binary operators / alignment.

Also, let's do a warnings.warn with a new bigframes.exceptions.PreviewWarning and add preview info to the docstrings to indicate that these features may change until we release them fully.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved on new PR today.


return self.distance(...)
68 changes: 68 additions & 0 deletions bigframes/geopandas/geoseries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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 shapely 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
>>> from shapely.geometry import Point
>>> import geopandas

>>> series = bigframes.pandas.Series(
... [shapely.Point(1, 1), shapely.Point(2, 2), shapely.Point(3, 3)],
... dtype=geopandas.array.GeometryDtype()
... )
>>> s.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
>>> from shapely.geometry import Point
>>> import geopandas

>>> series = bigframes.pandas.Series(
... [shapely.Point(1, 1), shapely.Point(2, 2), shapely.Point(3, 3)],
... dtype=geopandas.array.GeometryDtype()
... )
>>> s.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)
13 changes: 13 additions & 0 deletions bigframes/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import bigframes.dataframe
import bigframes.dtypes
import bigframes.formatting_helpers as formatter
import bigframes.geopandas
import bigframes.operations as ops
import bigframes.operations.aggregations as agg_ops
import bigframes.operations.base
Expand Down Expand Up @@ -84,6 +85,18 @@ def dtype(self):
def dtypes(self):
return self._dtype

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

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

"""
return bigframes.geopandas.GeoSeries(self)

@property
def loc(self) -> bigframes.core.indexers.LocSeriesIndexer:
return bigframes.core.indexers.LocSeriesIndexer(self)
Expand Down