GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: Add BigFrames.bigquery.st_regionstats method by tswast · Pull Request #2200 · google/bigframes

Conversation

@tswast

@tswast tswast commented Oct 27, 2025

Copy link
Copy Markdown
Collaborator

This commit adds the BigFrames.bigquery.st_regionstats method, which allows users to compute statistics for a raster band within a given geography.

The implementation includes:

  • A new StRegionStatsOp in bigframes/operations/geo_ops.py.
  • Compiler implementations for both the SQLGlot and Ibis backends.
  • A unit test with a SQL snapshot.
  • A code sample in samples/snippets/wildfire_risk.py that demonstrates the use of the new function.

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> 🦕

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@google-labs-jules
feat: Add BigFrames.bigquery.st_regionstats method
03a153c
This commit adds the `BigFrames.bigquery.st_regionstats` method, which allows users to compute statistics for a raster band within a given geography.

The implementation includes:
- A new `StRegionStatsOp` in `bigframes/operations/geo_ops.py`.
- Compiler implementations for both the SQLGlot and Ibis backends.
- A unit test with a SQL snapshot.
- A code sample in `samples/snippets/wildfire_risk.py` that demonstrates the use of the new function.
@tswast
tswast requested a review from a team as a code owner October 27, 2025 21:13
@tswast
tswast requested review from a team, glasnt and jialuoo October 27, 2025 21:13
@product-auto-label product-auto-label Bot added the size: l Pull request size is large. label Oct 27, 2025
@blunderbuss-gcf blunderbuss-gcf Bot assigned jialuoo Oct 27, 2025
@product-auto-label product-auto-label Bot added the api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. label Oct 27, 2025
tswast
tswast commented Oct 27, 2025
View reviewed changes
Comment thread bigframes/bigquery/_operations/geo.py Outdated
raster: bigframes.series.Series,
band: str,
*,
options: Mapping[str, Union[str, int, float]] = {},

@tswast tswast Oct 27, 2025

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Missing "include".

Also, "options" might not work if it is keyword-only.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@tswast tswast Oct 29, 2025

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Also, don't use mutable values as the default.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
tswast
tswast commented Oct 27, 2025
View reviewed changes
Comment thread bigframes/core/compile/ibis_compiler/scalar_op_compiler.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@gcf-owl-bot
🦉 Updates from OwlBot post-processor
ab46078
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
tswast
tswast commented Oct 27, 2025
View reviewed changes
Comment thread bigframes/core/compile/ibis_compiler/scalar_op_compiler.py Outdated
if op.options:
args.append(bigframes_vendored.ibis.literal(op.options, type="json"))
return bigframes_vendored.ibis.remote_function(
"st_regionstats", args, output_type="struct<min: float, max: float, sum: float, count: int, mean: float>" # type: ignore

@tswast tswast Oct 27, 2025

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Per https://cloud.google.com/bigquery/docs/reference/standard-sql/geography_functions#st_regionstats it should also include area.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
tswast
tswast commented Oct 27, 2025
View reviewed changes
Comment thread samples/snippets/wildfire_risk.py Outdated
# See the License for the specific language governing permissions and
# limitations under the License.

import bigframes.bigquery as bbq

@tswast tswast Oct 27, 2025

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Should put this inside a test file so we actually run it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
tswast
tswast commented Oct 27, 2025
View reviewed changes
Comment thread samples/snippets/wildfire_risk.py Outdated

@tswast tswast Oct 27, 2025

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Inspired by the SQL at https://cloud.google.com/blog/products/data-analytics/a-closer-look-at-earth-engine-in-bigquery

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
tswast
tswast commented Oct 27, 2025
View reviewed changes
Comment thread tests/unit/core/compile/sqlglot/test_geo_compiler.py Outdated
pytest.importorskip("pytest_snapshot")


class TestGeoCompiler:

@tswast tswast Oct 27, 2025

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Should use pytest style not unittest style.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
google-labs-jules Bot and others added 7 commits October 27, 2025 21:54
@google-labs-jules
feat: Add BigFrames.bigquery.st_regionstats method
92c69aa
This commit adds the `BigFrames.bigquery.st_regionstats` method, which allows users to compute statistics for a raster band within a given geography.

The implementation includes:
- A new `StRegionStatsOp` in `bigframes/operations/geo_ops.py`.
- Compiler implementations for both the SQLGlot and Ibis backends.
- A unit test with a SQL snapshot.
- A system test that demonstrates the use of the new function.

This commit also addresses feedback from the code review, including:
- Adding `area` to the output struct of `st_regionstats`.
- Making the `options` parameter a positional argument.
- Adding comments to explain the use of `pass_op`.
- Converting the unit test to a pytest-style function.
- Moving the sample code to a system test.
@tswast
Merge branch 'main' into feat-st-regionstats
8b681c0
@gcf-owl-bot
🦉 Updates from OwlBot post-processor
21243e4
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
@gcf-owl-bot
Merge branch 'feat-st-regionstats' of https://github.com/googleapis/p…
459c5b2
…ython-bigquery-dataframes into feat-st-regionstats
@gcf-owl-bot
🦉 Updates from OwlBot post-processor
350d241
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
@gcf-owl-bot
Merge branch 'feat-st-regionstats' of https://github.com/googleapis/p…
b4db49c
…ython-bigquery-dataframes into feat-st-regionstats
@google-labs-jules
feat: Add BigFrames.bigquery.st_regionstats method
a680526
This commit introduces the `st_regionstats` method in `bigframes.bigquery`, allowing users to compute statistics for a raster band within a given geography.

Key changes:
- Added `StRegionStatsOp` in `bigframes/operations/geo_ops.py`.
- Implemented compilation logic for the operation in both Ibis and SQLGlot compilers.
- Exposed the `st_regionstats` function in `bigframes/bigquery/_operations/geo.py` and the public API.
- Added a new `_apply_ternary_op` method to `bigframes.series.Series`.
- Included a unit test with a snapshot to verify the generated SQL.
- Added a system test that demonstrates the functionality by converting a complex wildfire risk analysis query from SQL to BigFrames.
- Refactored compiler registries to support `pass_op=True` for ternary operations, enabling access to operator parameters during compilation.
@review-notebook-app

review-notebook-app Bot commented Oct 28, 2025

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@product-auto-label product-auto-label Bot added size: xl Pull request size is extra large. and removed size: l Pull request size is large. labels Oct 28, 2025
tswast and others added 4 commits October 28, 2025 09:50
@tswast
Merge branch 'main' into feat-st-regionstats
9775fb6
@gcf-owl-bot
🦉 Updates from OwlBot post-processor
bcd4047
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
@gcf-owl-bot
🦉 Updates from OwlBot post-processor
01edd21
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
@gcf-owl-bot
Merge branch 'feat-st-regionstats' of https://github.com/googleapis/p…
bf00055
…ython-bigquery-dataframes into feat-st-regionstats
tswast
tswast commented Oct 28, 2025
View reviewed changes
Comment thread bigframes/bigquery/_operations/ai.py

@tswast tswast Oct 28, 2025

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Bad merge. Revert these changes.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
tswast
tswast commented Oct 28, 2025
View reviewed changes
Comment thread bigframes/display/anywidget.py

@tswast tswast Oct 28, 2025

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Needs to be reverted too.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@google-labs-jules
feat: Add BigFrames.bigquery.st_regionstats method
3c172bb
This commit introduces the `st_regionstats` method in `bigframes.bigquery`, allowing users to compute statistics for a raster band within a given geography.

Key changes:
- Added `StRegionStatsOp` in `bigframes/operations/geo_ops.py`.
- Implemented compilation logic for the operation in both Ibis and SQLGlot compilers.
- Exposed the `st_regionstats` function in `bigframes/bigquery/_operations/geo.py` and the public API.
- Added a new `_apply_ternary_op` method to `bigframes.series.Series`.
- Included a unit test with a snapshot to verify the generated SQL.
- Added a system test that demonstrates the functionality by converting a complex wildfire risk analysis query from SQL to BigFrames.
- Refactored compiler registries to support `pass_op=True` for ternary operations, enabling access to operator parameters during compilation.
@product-auto-label product-auto-label Bot added size: l Pull request size is large. and removed size: xl Pull request size is extra large. labels Oct 28, 2025
gcf-owl-bot Bot and others added 9 commits October 28, 2025 15:32
@gcf-owl-bot
🦉 Updates from OwlBot post-processor
13a67bd
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
@tswast
Merge remote-tracking branch 'origin/main' into feat-st-regionstats
6a4b1c9
@tswast
add arguments to st_regionstats and make it into a unary op
745211e
@tswast
move to geo_ops
4252e90
@tswast
fix the sqlgot compiler
b44d520
@tswast
fix sqlgot compiler
18a6c76
@tswast
attempt at ibis compiler
1b007b9
@tswast
use JSON literals for options parameter
2483e80
@tswast
fix sample
c8eb266
@snippet-bot

snippet-bot Bot commented Oct 29, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 1 region tag.
  • samples/snippets/st_regionstats_test.py:19, tag bigquery_dataframes_st_regionstats

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tswast and others added 3 commits October 29, 2025 20:56
@tswast
Merge remote-tracking branch 'origin/main' into feat-st-regionstats
6d436ff
@tswast
Merge branch 'main' into feat-st-regionstats
ad021b7
@gcf-owl-bot
🦉 Updates from OwlBot post-processor
7a57ddd
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
tswast
tswast commented Oct 30, 2025
View reviewed changes
Comment thread samples/snippets/st_regionstats_test.py
Comment on lines +41 to +43
# TODO: Add st_simplify when it is available in BigFrames.
# https://github.com/googleapis/python-bigquery-dataframes/issues/1497
# countries["simplified_geometry"] = bq.st_simplify(countries["geometry"], 10000)

@tswast tswast Oct 30, 2025

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I'd like to add st_simplify first so that this sample can work without any todos for us.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread samples/snippets/st_regionstats_test.py
# [START bigquery_dataframes_st_regionstats]
from typing import cast

import bigframes.bigquery as bq

@tswast tswast Oct 30, 2025

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Let's use bbq instead of bq.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@tswast tswast mentioned this pull request Oct 30, 2025
feat: add bigframes.bigquery.st_simplify #2210
Merged
@tswast

tswast commented Nov 4, 2025

Copy link
Copy Markdown
Collaborator Author

Closing in favor of #2228

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tswast tswast closed this Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@glasnt glasnt Awaiting requested review from glasnt glasnt was automatically assigned from googleapis/python-samples-reviewers
@jialuoo jialuoo Awaiting requested review from jialuoo

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@jialuoo jialuoo

Labels

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

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@tswast @jialuoo
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.