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

TST: Make test_sql.py parallelizable #60595

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
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 sqlite_engine tests parallelizable
  • Loading branch information
UmbertoFasci committed Dec 19, 2024
commit 0c51e041e694c8826b59a3380b2171ba2c1c7662
26 changes: 15 additions & 11 deletions pandas/tests/io/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -3848,12 +3848,13 @@ def test_read_sql_dtype(conn, request, func, dtype_backend):

def test_bigint_warning(sqlite_engine):
conn = sqlite_engine
table_uuid = table_uuid_gen("test_bigintwarning")
# test no warning for BIGINT (to support int64) is raised (GH7433)
df = DataFrame({"a": [1, 2]}, dtype="int64")
assert df.to_sql(name="test_bigintwarning", con=conn, index=False) == 2
assert df.to_sql(name=table_uuid, con=conn, index=False) == 2

with tm.assert_produces_warning(None):
sql.read_sql_table("test_bigintwarning", conn)
sql.read_sql_table(table_uuid, conn)


def test_valueerror_exception(sqlite_engine):
Expand All @@ -3865,6 +3866,7 @@ def test_valueerror_exception(sqlite_engine):

def test_row_object_is_named_tuple(sqlite_engine):
conn = sqlite_engine
table_uuid = table_uuid_gen("test_frame")
# GH 40682
# Test for the is_named_tuple() function
# Placed here due to its usage of sqlalchemy
Expand All @@ -3882,7 +3884,7 @@ def test_row_object_is_named_tuple(sqlite_engine):
BaseModel = declarative_base()

class Test(BaseModel):
__tablename__ = "test_frame"
__tablename__ = table_uuid
id = Column(Integer, primary_key=True)
string_column = Column(String(50))

Expand All @@ -3892,7 +3894,7 @@ class Test(BaseModel):
with Session() as session:
df = DataFrame({"id": [0, 1], "string_column": ["hello", "world"]})
assert (
df.to_sql(name="test_frame", con=conn, index=False, if_exists="replace")
df.to_sql(name=table_uuid, con=conn, index=False, if_exists="replace")
== 2
)
session.commit()
Expand All @@ -3905,7 +3907,7 @@ class Test(BaseModel):
def test_read_sql_string_inference(sqlite_engine):
conn = sqlite_engine
# GH#54430
table = "test"
table = table_uuid_gen("test")
df = DataFrame({"a": ["x", "y"]})
df.to_sql(table, con=conn, index=False, if_exists="replace")

Expand All @@ -3922,10 +3924,11 @@ def test_read_sql_string_inference(sqlite_engine):

def test_roundtripping_datetimes(sqlite_engine):
conn = sqlite_engine
table_uuid = table_uuid_gen("test")
# GH#54877
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 == "2020-12-31 12:00:00.000000"


Expand Down Expand Up @@ -4061,17 +4064,18 @@ def test_self_join_date_columns(postgresql_psycopg2_engine):

def test_create_and_drop_table(sqlite_engine):
conn = sqlite_engine
table_uuid = table_uuid_gen("drop_test_frame")
temp_frame = DataFrame({"one": [1.0, 2.0, 3.0, 4.0], "two": [4.0, 3.0, 2.0, 1.0]})
with sql.SQLDatabase(conn) as pandasSQL:
with pandasSQL.run_transaction():
assert pandasSQL.to_sql(temp_frame, "drop_test_frame") == 4
assert pandasSQL.to_sql(temp_frame, table_uuid) == 4

assert pandasSQL.has_table("drop_test_frame")
assert pandasSQL.has_table(table_uuid)

with pandasSQL.run_transaction():
pandasSQL.drop_table("drop_test_frame")
pandasSQL.drop_table(table_uuid)

assert not pandasSQL.has_table("drop_test_frame")
assert not pandasSQL.has_table(table_uuid)


def test_sqlite_datetime_date(sqlite_buildin):
Expand Down