8000 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

feat: add bigframes.bigquery.st_distance function #1637

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

Merged
merged 13 commits into from
Apr 22, 2025
Merged

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 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 as code owners April 21, 2025 21:55
@tswast tswast requested a review from chelsea-lin April 21, 2025 21:55
1 POLYGON ((1.97082 2.00002, 0 2, 0 0, 1.97082 2...
2 GEOMETRYCOLLECTION EMPTY
3 LINESTRING (0.99265 1.00781, 0 2)
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

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
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):

1 POLYGON ((0 0, 0.99954 1, 0 1, 0 0))
2 LINESTRING (0 0, 0.99954 1)
3 GEOMETRYCOLLECTION EMPTY
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