Skip to content
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

Fix: [Bug] NameError: name 'p' is not defined #15581 #17577

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

LucasTonetto
Copy link

Modification of the markdown parser method to remove "python" from the markdown before processing it, if it exists

Description

Fixes #15581
When VertexAI is used, the return of the markdown text passed to the parse_code_markdown function uses language markup. For example ```python df.columns```. The previous code only considered removing the backticks. Treatment has been implemented to remove the language markup when it is present. Additionally, for string type returns, the snippet parse_code_markdown(output, only_last=True)[0] only returned the first letter of the string.

Error example:

> Pandas Instructions:
\```
\```python
df.groupby('filial')['forma_pagamento'].agg(lambda x: x.value_counts().idxmax())
\```
\```
Traceback (most recent call last):
  File "C:\...\llama_index\.venv\Lib\site-packages\llama_index\experimental\query_engine\pandas\output_parser.py", line 63, in default_output_processor
    output_str = str(safe_eval(module_end_str, global_vars, local_vars))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\llama_index\.venv\Lib\site-packages\llama_index\experimental\exec_utils.py", line 159, in safe_eval
    return eval(__source, _get_restricted_globals(__globals), __locals)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 1, in <module>
NameError: name 'p' is not defined

Type of Change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Your pull-request will likely not be merged unless it is covered by some form of impactful unit testing.

  • I added new unit tests to cover this change
  • I believe this change is already covered by existing unit tests

Suggested Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added Google Colab support for the newly added notebooks.
  • My changes generate no new warnings
  • 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 ran make format; make lint to appease the lint gods

Modification of the markdown parser method to remove "python" from the markdown before processing it, if it exists
@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jan 22, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jan 23, 2025
@logan-markewich logan-markewich enabled auto-merge (squash) January 23, 2025 21:04
auto-merge was automatically disabled January 23, 2025 22:25

Head branch was pushed to by a user without write access

@LucasTonetto
Copy link
Author

@logan-markewich Apologies for the oversight. :(
This is my first pull request for a major project, and I was a bit anxious. The linting issue has been fixed. Please review the PR again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: NameError: name 'p' is not defined
3 participants