E52B feat: add `bigframes.bigquery.st_distance` function by tswast · Pull Request #1637 · googleapis/python-bigquery-dataframes · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@tswast
Copy link
Collaborator
@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 no 10BC0 t 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 as code owners April 21, 2025 21:55
@tswast tswast requested a review from chelsea-lin April 21, 2025 21:55
4 POINT (0 1)
dtype: geometry
Args:
Copy link
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.

dtype: Float64
Args:
series:
Copy link
Contributor

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

Copy link
Collaborator 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
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
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
Collaborator 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
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
Collaborator 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.

@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 join this conversation on GitHub. Already have an account? Sign in to comment

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

0