Skip to content

Conversation

@osushinekotan
Copy link

Fixes #4011

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

Problem:
When optimize_data_file=True is set on a CodeExecutor and a CSV file is uploaded, the auto-generated explore_df() function calls crop() which is not defined, causing a NameError.

Solution:
Add the crop function definition to _DATA_FILE_HELPER_LIB. The implementation is consistent with the existing crop function used elsewhere in the codebase.

Testing Plan

Manual End-to-End (E2E) Tests:

  1. Create an agent with a CodeExecutor that has optimize_data_file=True
  2. Upload a CSV file to the agent
  3. Verify the preprocessing code executes without NameError

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

The crop function definition added:

def crop(s: str, max_chars: int = 64) -> str:
  """Crops a string to max_chars characters."""
  return s[: max_chars - 3] + '...' if len(s) > max_chars else s

@google-cla
Copy link

google-cla bot commented Dec 24, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @osushinekotan, 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 addresses a critical bug where the CodeExecutor would fail with a NameError when processing CSV files with data optimization enabled. The core issue was the explore_df() function attempting to use a crop() function that was not defined within its execution context. The fix involves embedding the necessary crop function directly into the _DATA_FILE_HELPER_LIB, thereby ensuring smooth and error-free data preprocessing for users leveraging this feature.

Highlights

  • Bug Fix: Resolves a NameError that occurred when optimize_data_file=True was set on a CodeExecutor and a CSV file was uploaded, due to a missing crop() function call within explore_df().
  • Function Addition: The crop utility function has been added to the _DATA_FILE_HELPER_LIB to ensure it's available when explore_df() is executed.
  • Code Consistency: The newly added crop function's implementation is consistent with existing crop functions used elsewhere in the codebase.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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.

@adk-bot adk-bot added the core [Component] This issue is related to the core interface and implementation label Dec 24, 2025
@adk-bot
Copy link
Collaborator

adk-bot commented Dec 24, 2025

Response from ADK Triaging Agent

Hello @osushinekotan, thank you for your contribution!

Before we can merge this pull request, you'll need to sign the Contributor License Agreement (CLA). The cla/google check at the bottom of the PR is currently failing. Please visit https://cla.developers.google.com/ to sign the agreement.

Once the CLA is signed, we can proceed with the review. Thanks!

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 correctly fixes a NameError by adding the missing crop function to _DATA_FILE_HELPER_LIB. The change is straightforward and addresses the described issue. I've identified a minor bug in the implementation of the new crop function related to an edge case and have provided a suggestion to make it more robust.

def crop(s: str, max_chars: int = 64) -> str:
"""Crops a string to max_chars characters."""
return s[: max_chars - 3] + '...' if len(s) > max_chars else s
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The current implementation of crop has a bug when max_chars is less than 3. For example, if s = 'abc' and max_chars = 2, the function returns 'ab...', which has a length of 5, exceeding the specified max_chars.

To ensure the cropped string never exceeds max_chars, the logic should handle small values of max_chars as a special case, for instance by truncating the string without adding an ellipsis.

Suggested change
return s[: max_chars - 3] + '...' if len(s) > max_chars else s
if len(s) <= max_chars:
return s
if max_chars >= 3:
return s[:max_chars - 3] + '...'
return s[:max_chars]

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for catching this! Fixed to handle small max_chars values.
b3b1382

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core [Component] This issue is related to the core interface and implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: NameError 'crop' is not defined when using optimize_data_file=True with CSV upload

2 participants