Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

feat: add bigframes.bigquery.st_distance function#1637

Merged
tswast merged 13 commits intomainfrom
tswast-kmeans-sample
Apr 22, 2025
Merged

feat: add bigframes.bigquery.st_distance function#1637
tswast merged 13 commits intomainfrom
tswast-kmeans-sample

Conversation

@tswast
Copy link
Copy Markdown
Contributor

@tswast tswast commented Apr 21, 2025

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. labels Apr 21, 2025
@product-auto-label product-auto-label bot added size: l Pull request size is large. and removed size: m Pull request size is medium. labels Apr 21, 2025
@tswast tswast marked this pull request as ready for review April 21, 2025 21:55
@tswast tswast requested review from a team and chelsea-lin April 21, 2025 21:55
4 POINT (0 1)
dtype: geometry

Args:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Miss series argument here.

Comment thread bigframes/bigquery/_operations/geo.py Outdated
dtype: Float64

Args:
series:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: add type to the arguments:
series(bigframes.series.Series)
other (bigframes.series.Series or geometric object)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Updated to use | instead of or to reflect Python 3.10+ type checking syntax.

        series (bigframes.pandas.Series | bigframes.geopandas.GeoSeries):
            A series containing geography objects.
        other (bigframes.pandas.Series | bigframes.geopandas.GeoSeries | shapely.Geometry):

4 POINT (0 1)
dtype: geometry

Args:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Missing series argument here.

# we can.
@property
def area(self, crs=None) -> bigframes.series.Series: # type: ignore
"""[Not Implemented] Use ``bigframes.bigquery.st_area(series)``,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm curious why we cannot implement the similar methods for GeoSeries here?

Copy link
Copy Markdown
Contributor Author

@tswast tswast Apr 22, 2025

Choose a reason for hiding this comment

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

It's because BigQuery returns the value in meters, but in GeoPandas, it's based on the native coordinates. We're leaving it as not implemented until we can figure out how to be more "drop in" with regards to support for GeoPandas.


geobf_s1 = bigframes.geopandas.GeoSeries(data=data1)
geobf_s2 = bigframes.geopandas.GeoSeries(data=data2)
geobf_s_result = bbq.st_distance(geobf_s1, geobf_s2).to_pandas()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we expect st_distance throw an error if two GeoSeries has different numbers of rows? If so, can we try to verify that offline or in a simple test?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It should not. Instead, it should return null for the mismatched rows but that'd be a good test. Will add some.

Comment thread bigframes/dtypes.py Outdated
Comment thread bigframes/dtypes.py Outdated
Comment thread third_party/bigframes_vendored/geopandas/geoseries.py Outdated
@tswast tswast merged commit bf1ae70 into main Apr 22, 2025
24 checks passed
@tswast tswast deleted the tswast-kmeans-sample branch April 22, 2025 16:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants