@@ -2716,36 +2716,40 @@ def test_delete_rows_success(conn, test_frame1, request):
2716
2716
assert pandasSQL .has_table ("temp_frame" )
2717
2717
2718
2718
2719
- @pytest .mark .parametrize ("conn " , all_connectable )
2720
- def test_delete_rows_is_atomic (conn , request ):
2719
+ @pytest .mark .parametrize ("conn_name " , all_connectable )
2720
+ def test_delete_rows_is_atomic (conn_name , request ):
2721
2721
adbc_driver_manager = pytest .importorskip ("adbc_driver_manager" )
2722
2722
sqlalchemy = pytest .importorskip ("sqlalchemy" )
2723
2723
2724
- if "sqlite" in conn :
2725
- reason = "This test relies on strict column types, SQLite has a dynamic one"
2726
- request .applymarker (
2727
- pytest .mark .xfail (
2728
- reason = reason ,
2729
- strict = True ,
2730
- )
2731
- )
2732
-
2733
2724
table_name = "temp_frame"
2734
- original_df = DataFrame ({"a" : [1 , 2 , 3 ]})
2735
- replacing_df = DataFrame ({"a" : ["a" , "b" , "c" , "d" ]})
2725
+ table_stmt = f"CREATE TABLE { table_name } (a INTEGER, b INTEGER UNIQUE NOT NULL)"
2736
2726
2737
- conn = request .getfixturevalue (conn )
2727
+ if conn_name != "sqlite_buildin" and "adbc" not in conn_name :
2728
+ table_stmt = sqlalchemy .text (table_stmt )
2729
+
2730
+ # setting dtype is mandatory for adbc related tests
2731
+ original_df = DataFrame ({"a" : [1 , 2 ], "b" : [3 , 4 ]}, dtype = "int32" )
2732
+ replacing_df = DataFrame ({"a" : [5 , 6 ], "b" : [7 , 7 ]}, dtype = "int32" )
2733
+
2734
+ conn = request .getfixturevalue (conn_name )
2738
2735
pandasSQL = pandasSQL_builder (conn )
2739
2736
2740
- if isinstance (conn , adbc_driver_manager .dbapi .Connection ):
2737
+ with pandasSQL .run_transaction () as cur :
2738
+ cur .execute (table_stmt )
2739
+
2740
+ if conn_name != "sqlite_buildin" and "adbc" not in conn_name :
2741
+ expected_exception = sqlalchemy .exc .IntegrityError
2742
+ elif "adbc" in conn_name and "sqlite" in conn_name :
2743
+ expected_exception = adbc_driver_manager .InternalError
2744
+ elif "adbc" in conn_name and "postgres" in conn_name :
2741
2745
expected_exception = adbc_driver_manager .ProgrammingError
2742
- else :
2743
- expected_exception = sqlalchemy . exc . DataError
2746
+ elif conn_name == "sqlite_buildin" :
2747
+ expected_exception = sqlite3 . IntegrityError
2744
2748
2745
2749
with pandasSQL .run_transaction ():
2746
- pandasSQL .to_sql (original_df , table_name , if_exists = "fail " , index = False )
2750
+ pandasSQL .to_sql (original_df , table_name , if_exists = "append " , index = False )
2747
2751
2748
- # trying to insert strings in an integer column
2752
+ # inserting duplicated values in a UNIQUE constraint column
2749
2753
with pytest .raises (expected_exception ):
2750
2754
with pandasSQL .run_transaction ():
2751
2755
pandasSQL .to_sql (
@@ -2754,7 +2758,7 @@ def test_delete_rows_is_atomic(conn, request):
2754
2758
2755
2759
# failed "delete_rows" is rolled back preserving original data
2756
2760
with pandasSQL .run_transaction ():
2757
- result_df = pandasSQL .read_query (f"SELECT * FROM { table_name } " )
2761
+ result_df = pandasSQL .read_query (f"SELECT * FROM { table_name } " , dtype = "int32" )
2758
2762
tm .assert_frame_equal (result_df , original_df )
2759
2763
2760
2764
0 commit comments