@@ -4361,40 +4361,43 @@ def test_xsqlite_if_exists(sqlite_buildin):
43614361
43624362
43634363@pytest .mark .parametrize ("con" , all_connectable )
4364- def test_bytes_column (con , request ):
4364+ @pytest .mark .parametrize ("dtype_backend" , ["pyarrow" , "numpy_nullable" , lib .no_default ])
4365+ def test_bytes_column (con , dtype_backend , request ):
43654366 # GitHub Issue #59242
43664367 conn = request .getfixturevalue (con )
43674368 pa = pytest .importorskip ("pyarrow" )
4368- for dtype_backend in ["pyarrow" , "numpy_nullable" , lib .no_default ]:
4369- df = pd .read_sql (
4370- "select x'0123456789abcdef0123456789abcdef' a" ,
4371- conn ,
4372- dtype_backend = dtype_backend ,
4373- )
4374-
4375- dtype = "O"
4376- val = b"\x01 #Eg\x89 \xab \xcd \xef \x01 #Eg\x89 \xab \xcd \xef "
43774369
4378- if "postgres" in con :
4379- val = (
4380- b"\x00 \x00 \x00 \x80 \x01 #Eg\x89 \xab \xcd \xef \x01 #Eg\x89 \xab \xcd \xef "
4381- if "adbc" in con
4382- else "0000000100100011010001010110011110001001101010"
4383- "11110011011110111100000001001000110100010101100"
4384- "11110001001101010111100110111101111"
4385- )
4386-
4387- if "psycopg2" in con and dtype_backend == "numpy_nullable" :
4388- dtype = pd .StringDtype ()
4370+ dtype = "O"
4371+ val = b"\x01 #Eg\x89 \xab \xcd \xef \x01 #Eg\x89 \xab \xcd \xef "
43894372
4373+ if "postgres" in con :
4374+ val = (
4375+ b"\x00 \x00 \x00 \x80 \x01 #Eg\x89 \xab \xcd \xef \x01 #Eg\x89 \xab \xcd \xef "
4376+ if "adbc" in con
4377+ else "0000000100100011010001010110011110001001101010"
4378+ "11110011011110111100000001001000110100010101100"
4379+ "11110001001101010111100110111101111"
4380+ )
43904381 if dtype_backend == "pyarrow" :
43914382 dtype = (
43924383 pd .ArrowDtype (pa .string ())
4393- if "postgres" in con and " adbc" not in con
4384+ if "adbc" not in con
43944385 else pd .ArrowDtype (pa .opaque (pa .binary (), "bit" , "PostgreSQL" ))
4395- if "postgres" in con
4396- else pd .ArrowDtype (pa .binary ())
43974386 )
43984387
4399- expected = DataFrame ([{"a" : val }], dtype = dtype )
4400- tm .assert_frame_equal (df , expected )
4388+ if "psycopg2" in con :
4389+ if dtype_backend == "numpy_nullable" :
4390+ dtype = pd .StringDtype ()
4391+ elif dtype_backend == lib .no_default and pd .options .future .infer_string :
4392+ dtype = pd .StringDtype (storage = "pyarrow" , na_value = np .nan )
4393+
4394+ if "postgres" not in con and dtype_backend == "pyarrow" :
4395+ dtype = pd .ArrowDtype (pa .binary ())
4396+
4397+ expected = DataFrame ([{"a" : val }], dtype = dtype )
4398+ df = pd .read_sql (
4399+ "select x'0123456789abcdef0123456789abcdef' a" ,
4400+ conn ,
4401+ dtype_backend = dtype_backend ,
4402+ )
4403+ tm .assert_frame_equal (df , expected )
0 commit comments