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[PostgreSQLConnector]: Rand() not supported in postgresql #570

Merged
merged 1 commit into from
Sep 18, 2023

Conversation

ArslanSaleem
Copy link
Collaborator

@ArslanSaleem ArslanSaleem commented Sep 18, 2023

PostgreSQLConnector broken:

  • Rand() not supported in Postgresql

Summary by CodeRabbit

  • New Feature: Added a head() method to the SQL connector in the pandasai library. This feature allows users to quickly preview the first five rows of their data source, returned as a DataFrame. This enhancement improves data exploration and debugging capabilities by providing an easy way to inspect the initial data from the connected SQL source.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 18, 2023

Walkthrough

The proposed change introduces a new head() method to the SQL connector class in the pandasai library. This method fetches and returns the first five rows of the connected data source as a DataFrame, providing a quick snapshot of the data.

Changes

File Summary
pandasai/connectors/sql.py Added a head() method to retrieve the first five rows from the connected data source as a DataFrame.

🐇💻

In the land of code where the shadows lie,
A rabbit hopped forth under the cloudless sky.
With a twitch of its nose and a flick of its ear,
It conjured a function clear and dear.

Five rows it fetched, not one row more,
From the vast data lake's endless shore.
Into a DataFrame, the data did pour,
A glimpse of the treasure that lies in store. 📜🔍


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • Mention @coderabbitai in any review comment for bot assistance.
  • Note: Review comments are made on code diffs or files, not on the PR overview.

Pause Incremental Reviews

  • Insert @coderabbitai: ignore in the PR description to halt the bot's ongoing reviews. Remove the line to resume.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Commits Files that changed from the base of the PR and between 390c597 and fd1fb4d commits.
Files selected for processing (1)
  • pandasai/connectors/sql.py (1 hunks)
Additional comments (Suppressed): 3
pandasai/connectors/sql.py (3)
  • 391-393: The changes in these lines are acceptable. The POSTGRESQL_PASSWORD is being fetched from the environment variables and passed to the parent class constructor.

  • 396-415: The new head() method fetches the first few rows of data from the connected data source and returns it as a DataFrame. It does this by executing a SQL query to fetch the column names and five random rows from the data source. This change ensures compatibility with PostgreSQL by avoiding the use of unsupported functions while maintaining the functionality of fetching random data samples.

  • 414-415: The pd.read_sql(query, self._connection) function call is used to execute the SQL query and return the result as a DataFrame. Ensure that the _connection attribute is properly initialized before this line is executed. If the connection fails for any reason (e.g., incorrect credentials, network issues), this line could raise an exception. Make sure to handle such potential exceptions appropriately.

pandasai/connectors/sql.py Show resolved Hide resolved
@codecov-commenter
Copy link

Codecov Report

Merging #570 (fd1fb4d) into main (390c597) will decrease coverage by 0.12%.
The diff coverage is 33.33%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

@@            Coverage Diff             @@
##             main     #570      +/-   ##
==========================================
- Coverage   83.45%   83.33%   -0.12%     
==========================================
  Files          53       53              
  Lines        2599     2605       +6     
==========================================
+ Hits         2169     2171       +2     
- Misses        430      434       +4     
Files Changed Coverage Δ
pandasai/connectors/sql.py 58.72% <33.33%> (-0.92%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@gventuri gventuri merged commit 4e0aadb into main Sep 18, 2023
9 checks passed
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.

3 participants