Skip to content

Conversation

@parthea
Copy link
Contributor

@parthea parthea commented Jan 23, 2026

WIP

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @parthea, 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 focuses on improving the type checking robustness of the google-cloud-automl library by addressing existing mypy errors. It refines how optional dependencies are handled and ensures that mypy has the necessary type information for external libraries, leading to a cleaner and more reliable codebase.

Highlights

  • Refactored Optional Dependency Checks: The pull request refactors how optional dependencies (pandas and google.cloud.storage) are checked for availability in gcs_client.py. Instead of checking if the imported module is None, dedicated boolean flags (_PANDAS_INSTALLED and _STORAGE_INSTALLED) are now used to indicate successful import.
  • Mypy Type Ignore for Google Cloud Storage: A type: ignore comment has been added to the google.cloud.storage import statement in gcs_client.py to suppress mypy errors related to a known upstream issue, ensuring smoother type checking.
  • Added Pandas Type Stubs: The noxfile.py has been updated to include pandas-stubs in the mypy session dependencies. This provides necessary type information for the pandas library, improving the accuracy and completeness of static type analysis.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request aims to fix mypy errors, and the changes in noxfile.py to add pandas-stubs are correct. However, the changes in google/cloud/automl_v1beta1/services/tables/gcs_client.py to handle optional dependencies using boolean flags introduce a new problem for static analysis: mypy will report a NameError because the module names (pandas, storage) are not defined if their respective imports fail.

I've provided suggestions to revert to the more standard pattern of setting the module variable to None on ImportError. This resolves the NameError for mypy. The type: ignore for the storage import is preserved as it seems necessary to resolve a separate mypy issue with that library. With these changes, the mypy errors should be correctly resolved.

Comment on lines 24 to +36
try:
import pandas
_PANDAS_INSTALLED = True
except ImportError: # pragma: NO COVER
pandas = None
_PANDAS_INSTALLED = False

try:
from google.cloud import storage
# TODO(https://github.com/googleapis/python-storage/issues/318):
# Remove `type: ignore` once this bug is fixed
from google.cloud import storage # type: ignore
_STORAGE_INSTALLED = True
except ImportError: # pragma: NO COVER
storage = None
_STORAGE_INSTALLED = False
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This approach of using boolean flags to track optional dependencies can introduce a NameError for static type checkers like mypy. If an import fails, the module name is not defined, which will cause a mypy error on later usage (e.g., pandas.DataFrame).

The original pattern of setting the module to None on ImportError is more robust. The mypy errors can be fixed by other means. For storage, the type: ignore you've added is correct. For pandas, mypy should correctly handle the if pandas is None: raise type guard, especially with pandas-stubs installed.

I suggest reverting this block to the conventional pattern, which will also require reverting the checks below.

Suggested change
try:
import pandas
_PANDAS_INSTALLED = True
except ImportError: # pragma: NO COVER
pandas = None
_PANDAS_INSTALLED = False
try:
from google.cloud import storage
# TODO(https://github.com/googleapis/python-storage/issues/318):
# Remove `type: ignore` once this bug is fixed
from google.cloud import storage # type: ignore
_STORAGE_INSTALLED = True
except ImportError: # pragma: NO COVER
storage = None
_STORAGE_INSTALLED = False
try:
import pandas
except ImportError: # pragma: NO COVER
pandas = None
try:
# TODO(https://github.com/googleapis/python-storage/issues/318):
# Remove `type: ignore` once this bug is fixed
from google.cloud import storage # type: ignore
except ImportError: # pragma: NO COVER
storage = None

environment.
"""
if storage is None:
if not _STORAGE_INSTALLED:
Copy link
Contributor

Choose a reason for hiding this comment

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

high

To align with the suggested change to the import pattern, this check should be reverted to if storage is None:.

Suggested change
if not _STORAGE_INSTALLED:
if storage is None:

A string representing the GCS URI of the uploaded CSV.
"""
if pandas is None:
if not _PANDAS_INSTALLED:
Copy link
Contributor

Choose a reason for hiding this comment

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

high

To align with the suggested change to the import pattern, this check should be reverted to if pandas is None:.

Suggested change
if not _PANDAS_INSTALLED:
if pandas is None:

@parthea parthea closed this Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant