Skip to content

TST: Make test_sql.py parallelizable #60595

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 17 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
0fe741b
Make test_sql.py all_connectable tests parallelizable
UmbertoFasci Dec 8, 2024
60f1a14
Make test_sql.py sqlalchemy_connectable tests parallelizable
UmbertoFasci Dec 9, 2024
cc35414
Make test_sql.py postgresql_connectable tests parallelizable
UmbertoFasci Dec 9, 2024
ecb6c4d
make test_sql.py mysql_connectable tests parallelizable
UmbertoFasci Dec 9, 2024
0c51e04
Make test_sql.py sqlite_engine tests parallelizable
UmbertoFasci Dec 19, 2024
17cf723
Make test_sql.py sqlite_conn tests parallelizable
UmbertoFasci Dec 19, 2024
4147a77
Make test_sql.py other connectable tests parallelizable
UmbertoFasci Dec 20, 2024
5250e1b
Make test_sql.py other connectable tests parallelizable 2
UmbertoFasci Dec 20, 2024
6d73fa0
Make test_sql.py other connectable tests parallelizable 3
UmbertoFasci Dec 20, 2024
9c9f7e7
Merge branch 'main' into make_parallelizable
UmbertoFasci Dec 20, 2024
a354c59
Remove single CPU marker and update table name creation function name
UmbertoFasci Dec 20, 2024
b18c79c
resolve test_api_to_sql_index_label_multiindex error
UmbertoFasci Dec 20, 2024
2a856db
resolve tests which create table with create_and_load_postgres_datetz
UmbertoFasci Dec 20, 2024
7a31438
resolve regex error for test_xsqlite_if_exists
UmbertoFasci Dec 20, 2024
b5a60d9
resolve sqlalchemy reflection drop_table race condition
UmbertoFasci Dec 21, 2024
be28090
resolve drop_table sqlalchemy reflection error handling
UmbertoFasci Dec 21, 2024
e62a848
revert drop_table error handling
UmbertoFasci Dec 21, 2024
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
Prev Previous commit
Next Next commit
Make test_sql.py other connectable tests parallelizable 2
  • Loading branch information
UmbertoFasci committed Dec 20, 2024
commit 5250e1bd8f4cba0e24c7adb9a2534ac28f3d0168
34 changes: 20 additions & 14 deletions pandas/tests/io/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1508,25 +1508,28 @@ def test_read_view_postgres(conn, request):

def test_read_view_sqlite(sqlite_buildin):
# GH 52969
create_table = """
CREATE TABLE groups (
table_uuid = table_uuid_gen("groups")
view_uuid = table_uuid_gen("group_view")

create_table = f"""
CREATE TABLE {table_uuid} (
group_id INTEGER,
name TEXT
);
"""
insert_into = """
INSERT INTO groups VALUES
insert_into = f"""
INSERT INTO {table_uuid} VALUES
(1, 'name');
"""
create_view = """
CREATE VIEW group_view
create_view = f"""
CREATE VIEW {view_uuid}
AS
SELECT * FROM groups;
SELECT * FROM {table_uuid};
"""
sqlite_buildin.execute(create_table)
sqlite_buildin.execute(insert_into)
sqlite_buildin.execute(create_view)
result = pd.read_sql("SELECT * FROM group_view", sqlite_buildin)
result = pd.read_sql(f"SELECT * FROM {view_uuid}", sqlite_buildin)
expected = DataFrame({"group_id": [1], "name": "name"})
tm.assert_frame_equal(result, expected)

Expand Down Expand Up @@ -3947,9 +3950,10 @@ def sqlite_builtin_detect_types():
def test_roundtripping_datetimes_detect_types(sqlite_builtin_detect_types):
# https://github.com/pandas-dev/pandas/issues/55554
conn = sqlite_builtin_detect_types
table_uuid = table_uuid_gen("test")
df = DataFrame({"t": [datetime(2020, 12, 31, 12)]}, dtype="datetime64[ns]")
df.to_sql("test", conn, if_exists="replace", index=False)
result = pd.read_sql("select * from test", conn).iloc[0, 0]
df.to_sql(table_uuid, conn, if_exists="replace", index=False)
result = pd.read_sql(f"select * from {table_uuid}", conn).iloc[0, 0]
assert result == Timestamp("2020-12-31 12:00:00.000000")


Expand Down Expand Up @@ -4238,8 +4242,10 @@ def test_xsqlite_basic(sqlite_buildin):
columns=Index(list("ABCD")),
index=date_range("2000-01-01", periods=10, freq="B"),
)
assert sql.to_sql(frame, name="test_table", con=sqlite_buildin, index=False) == 10
result = sql.read_sql("select * from test_table", sqlite_buildin)
table_uuid = table_uuid_gen("test_table")
table_uuid2 = table_uuid_gen("test_table2")
assert sql.to_sql(frame, name=table_uuid, con=sqlite_buildin, index=False) == 10
result = sql.read_sql(f"select * from {table_uuid}", sqlite_buildin)

# HACK! Change this once indexes are handled properly.
result.index = frame.index
Expand All @@ -4251,8 +4257,8 @@ def test_xsqlite_basic(sqlite_buildin):
frame2 = frame.copy()
new_idx = Index(np.arange(len(frame2)), dtype=np.int64) + 10
frame2["Idx"] = new_idx.copy()
assert sql.to_sql(frame2, name="test_table2", con=sqlite_buildin, index=False) == 10
result = sql.read_sql("select * from test_table2", sqlite_buildin, index_col="Idx")
assert sql.to_sql(frame2, name=table_uuid2, con=sqlite_buildin, index=False) == 10
result = sql.read_sql(f"select * from {table_uuid2}", sqlite_buildin, index_col="Idx")
expected = frame.copy()
expected.index = new_idx
expected.index.name = "Idx"
Expand Down