feat: add bigframes calling Python UDF code sample#13919
feat: add bigframes calling Python UDF code sample#13919tswast wants to merge 8 commits intoGoogleCloudPlatform:mainfrom
Conversation
This sample is intended for https://docs.cloud.google.com/bigquery/docs/user-defined-functions-python#udf_users See internal issue b/494558638.
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a new, self-contained code sample within the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new bigquery/bigframes directory, adding a README, a test for calling Python UDFs, pytest fixtures, nox configuration, and dependency files. The review comments suggest improving the formatting of multiline XML strings in call_python_udf_test.py for clarity, making the --project_id argument required in the test script to prevent unexpected behavior, and setting enforce_type_hints to True in noxfile_config.py to align with project standards for new samples.
| xml_series = bpd.Series( | ||
| [ | ||
| ''' | ||
| <book id="1"> | ||
| <title>The Great Gatsby</title> | ||
| <author>F. Scott Fitzgerald</author> | ||
| </book> | ||
| ''', | ||
| ''' | ||
| <book id="2"> | ||
| <title>1984</title> | ||
| <author>George Orwell</author> | ||
| </book> | ||
| ''', | ||
| ''' | ||
| <book id="3"> | ||
| <title>Brave New World</title> | ||
| <author>Aldous Huxley</author> | ||
| </book> | ||
| ''', | ||
| ] | ||
| ) |
There was a problem hiding this comment.
The multiline string literals for xml_series contain significant leading whitespace and newlines due to Python's indentation. While the XML parser might handle this, it's best practice to provide clean data and avoid ambiguity. This also improves the readability and maintainability of the sample code.
xml_series = bpd.Series(
[
"""<book id="1">
<title>The Great Gatsby</title>
<author>F. Scott Fitzgerald</author>
</book>""",
"""<book id="2">
<title>1984</title>
<author>George Orwell</author>
</book>""",
"""<book id="3">
<title>Brave New World</title>
<author>Aldous Huxley</author>
</book>""",
]
)There was a problem hiding this comment.
I disagree. It looks better with the whitespace.
| import argparse | ||
|
|
||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("--project_id", type=str) |
There was a problem hiding this comment.
When running this test file as a standalone script, the --project_id argument is not marked as required. If a user forgets to provide it, it will default to None, which might lead to unexpected behavior or errors if a default project cannot be inferred from the environment. It's better to fail fast by making it a required argument.
| parser.add_argument("--project_id", type=str) | |
| parser.add_argument("--project_id", type=str, required=True) |
There was a problem hiding this comment.
None is OK. Then it uses the project from ADC.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This sample is intended for https://docs.cloud.google.com/bigquery/docs/user-defined-functions-python#udf_users See internal issue b/494558638.
Description
Fixes #
Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.
Checklist
nox -s py-3.9(see Test Environment Setup)nox -s lint(see Test Environment Setup)