Skip to content

Inconsistent index between plain DataFrame and read_sql DataFrame #48193

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

Closed
wants to merge 8 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions pandas/tests/io/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -2972,3 +2972,20 @@ def test_if_exists(self):
(5, "E"),
]
self.drop_table(table_name)

def test_index_consistency_df_and_sql_df(self):
# GH47608
cur = self.conn.cursor()

cur.execute("CREATE TABLE data (id int, val real)")
cur.execute("INSERT INTO data VALUES (1, 150.0), (2, 160.0)")
self.conn.commit()

result = pd.read_sql("SELECT * FROM data", self.conn)
expected = DataFrame({"id": [1, 2], "val": [150.0, 160.0]})
tm.assert_frame_equal(result, expected)

result = pd.read_sql("SELECT * FROM data WHERE (1 = 0)", self.conn)

expected = DataFrame({"id": [], "val": []})
tm.assert_frame_equal(result, expected)