Skip to content

Remove dict and use yfinance data for company mapping instead#312

Open
zaynfuture wants to merge 1 commit intoTauricResearch:mainfrom
zaynfuture:main
Open

Remove dict and use yfinance data for company mapping instead#312
zaynfuture wants to merge 1 commit intoTauricResearch:mainfrom
zaynfuture:main

Conversation

@zaynfuture
Copy link

When I tested using TEM, I found that the tool analyzed TEM as TSM. After investigating, I learned that this behavior was controlled by the ticker_to_company logic. Therefore, this part has been replaced with company name resolution using open-source data from yfinance.

@gemini-code-assist
Copy link

Summary of Changes

Hello @zaynfuture, 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 refactors the company name resolution logic within the reddit_utils.py module. It transitions from using a static, manually maintained dictionary for mapping stock tickers to company names to leveraging the yfinance library for dynamic and more accurate company information retrieval. This change aims to prevent misidentifications, such as 'TEM' being incorrectly analyzed as 'TSM', by relying on an external, up-to-date data source.

Highlights

  • Company Name Resolution: The static ticker_to_company dictionary has been removed and replaced with dynamic company name resolution using the yfinance library.
  • Accuracy Improvement: This change addresses issues where tickers like 'TEM' were incorrectly mapped, ensuring more accurate identification of companies based on their stock tickers.
  • Dependency Update: The yfinance library has been introduced as a new dependency to fetch up-to-date company information.

🧠 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.

Copy link

@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 improve robustness and maintainability by replacing a hardcoded ticker-to-company mapping with dynamic data fetching from yfinance. However, a critical command injection vulnerability has been identified in tradingagents/dataflows/reddit_utils.py. This vulnerability arises because user-supplied input is passed to the yfinance library without proper sanitization, which could lead to remote code execution. It is crucial to remediate this by validating user input before it is processed by the external library. Additionally, the review suggests fixing a bug that creates duplicate search terms and improving error handling by logging exceptions instead of silently ignoring them.

else:
search_terms = [ticker_to_company[query]]
try:
info = yf.Ticker(query).info or {}

Choose a reason for hiding this comment

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

security-critical critical

The query parameter, which can be controlled by the user, is passed directly to the yf.Ticker() constructor. Certain versions of the yfinance library are susceptible to OS command injection vulnerabilities via the ticker symbol. An attacker could potentially inject malicious commands by providing a specially crafted query string, leading to arbitrary command execution on the server. It is recommended to sanitize the query input by validating it against a known list of safe ticker symbols or by using a regex to allow only alphanumeric characters.

if company_name:
search_terms.insert(0, company_name)

search_terms.append(query)

Choose a reason for hiding this comment

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

high

The ticker symbol (query) is added to search_terms twice. It's first added at line 67, and then again at this line. This is redundant and leads to search_terms containing duplicate entries (e.g., ['Apple Inc.', 'AAPL', 'AAPL'] if the company name is found). You can safely remove this line to fix the duplication.

Comment on lines +64 to +65
except Exception:
company_name = None

Choose a reason for hiding this comment

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

medium

It's good practice to log exceptions, even if you are handling them gracefully. Silently catching all exceptions can hide underlying issues with the yfinance API, network connectivity, or invalid tickers that don't behave as expected. Consider printing a warning message to make debugging easier in the future.

Suggested change
except Exception:
company_name = None
except Exception as e:
print(f"Warning: Could not fetch company name for ticker '{query}' from yfinance: {e}")
company_name = None

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