2828 read_json ,
2929)
3030import pandas ._testing as tm
31- from pandas .core .arrays import (
32- ArrowStringArray ,
33- StringArray ,
34- )
35- from pandas .core .arrays .string_arrow import ArrowStringArrayNumpySemantics
3631
3732from pandas .io .json import ujson_dumps
3833
@@ -2143,12 +2138,10 @@ def test_json_uint64(self):
21432138 result = df .to_json (orient = "split" )
21442139 assert result == expected
21452140
2146- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" , strict = False )
21472141 def test_read_json_dtype_backend (
21482142 self , string_storage , dtype_backend , orient , using_infer_string
21492143 ):
21502144 # GH#50750
2151- pa = pytest .importorskip ("pyarrow" )
21522145 df = DataFrame (
21532146 {
21542147 "a" : Series ([1 , np .nan , 3 ], dtype = "Int64" ),
@@ -2162,30 +2155,18 @@ def test_read_json_dtype_backend(
21622155 }
21632156 )
21642157
2165- if using_infer_string :
2166- string_array = ArrowStringArrayNumpySemantics (pa .array (["a" , "b" , "c" ]))
2167- string_array_na = ArrowStringArrayNumpySemantics (pa .array (["a" , "b" , None ]))
2168- elif string_storage == "python" :
2169- string_array = StringArray (np .array (["a" , "b" , "c" ], dtype = np .object_ ))
2170- string_array_na = StringArray (np .array (["a" , "b" , NA ], dtype = np .object_ ))
2171-
2172- elif dtype_backend == "pyarrow" :
2173- pa = pytest .importorskip ("pyarrow" )
2174- from pandas .arrays import ArrowExtensionArray
2175-
2176- string_array = ArrowExtensionArray (pa .array (["a" , "b" , "c" ]))
2177- string_array_na = ArrowExtensionArray (pa .array (["a" , "b" , None ]))
2178-
2179- else :
2180- string_array = ArrowStringArray (pa .array (["a" , "b" , "c" ]))
2181- string_array_na = ArrowStringArray (pa .array (["a" , "b" , None ]))
2182-
21832158 out = df .to_json (orient = orient )
21842159 with pd .option_context ("mode.string_storage" , string_storage ):
21852160 result = read_json (
21862161 StringIO (out ), dtype_backend = dtype_backend , orient = orient
21872162 )
21882163
2164+ if dtype_backend == "pyarrow" :
2165+ pa = pytest .importorskip ("pyarrow" )
2166+ string_dtype = pd .ArrowDtype (pa .string ())
2167+ else :
2168+ string_dtype = pd .StringDtype (string_storage )
2169+
21892170 expected = DataFrame (
21902171 {
21912172 "a" : Series ([1 , np .nan , 3 ], dtype = "Int64" ),
@@ -2194,12 +2175,13 @@ def test_read_json_dtype_backend(
21942175 "d" : Series ([1.5 , 2.0 , 2.5 ], dtype = "Float64" ),
21952176 "e" : Series ([True , False , NA ], dtype = "boolean" ),
21962177 "f" : Series ([True , False , True ], dtype = "boolean" ),
2197- "g" : string_array ,
2198- "h" : string_array_na ,
2178+ "g" : Series ([ "a" , "b" , "c" ], dtype = string_dtype ) ,
2179+ "h" : Series ([ "a" , "b" , None ], dtype = string_dtype ) ,
21992180 }
22002181 )
22012182
22022183 if dtype_backend == "pyarrow" :
2184+ pa = pytest .importorskip ("pyarrow" )
22032185 from pandas .arrays import ArrowExtensionArray
22042186
22052187 expected = DataFrame (
0 commit comments