3131 read_json ,
3232)
3333import pandas ._testing as tm
34- from pandas .core .arrays import (
35- ArrowStringArray ,
36- StringArray ,
37- )
38- from pandas .core .arrays .string_arrow import ArrowStringArrayNumpySemantics
3934
4035from pandas .io .json import ujson_dumps
4136
@@ -2037,14 +2032,10 @@ def test_json_uint64(self):
20372032 assert result == expected
20382033
20392034 @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" , strict = False )
2040- @pytest .mark .parametrize (
2041- "orient" , ["split" , "records" , "values" , "index" , "columns" ]
2042- )
20432035 def test_read_json_dtype_backend (
20442036 self , string_storage , dtype_backend , orient , using_infer_string
20452037 ):
20462038 # GH#50750
2047- pa = pytest .importorskip ("pyarrow" )
20482039 df = DataFrame (
20492040 {
20502041 "a" : Series ([1 , np .nan , 3 ], dtype = "Int64" ),
@@ -2058,30 +2049,18 @@ def test_read_json_dtype_backend(
20582049 }
20592050 )
20602051
2061- if using_infer_string :
2062- string_array = ArrowStringArrayNumpySemantics (pa .array (["a" , "b" , "c" ]))
2063- string_array_na = ArrowStringArrayNumpySemantics (pa .array (["a" , "b" , None ]))
2064- elif string_storage == "python" :
2065- string_array = StringArray (np .array (["a" , "b" , "c" ], dtype = np .object_ ))
2066- string_array_na = StringArray (np .array (["a" , "b" , NA ], dtype = np .object_ ))
2067-
2068- elif dtype_backend == "pyarrow" :
2069- pa = pytest .importorskip ("pyarrow" )
2070- from pandas .arrays import ArrowExtensionArray
2071-
2072- string_array = ArrowExtensionArray (pa .array (["a" , "b" , "c" ]))
2073- string_array_na = ArrowExtensionArray (pa .array (["a" , "b" , None ]))
2074-
2075- else :
2076- string_array = ArrowStringArray (pa .array (["a" , "b" , "c" ]))
2077- string_array_na = ArrowStringArray (pa .array (["a" , "b" , None ]))
2078-
20792052 out = df .to_json (orient = orient )
20802053 with pd .option_context ("mode.string_storage" , string_storage ):
20812054 result = read_json (
20822055 StringIO (out ), dtype_backend = dtype_backend , orient = orient
20832056 )
20842057
2058+ if dtype_backend == "pyarrow" :
2059+ pa = pytest .importorskip ("pyarrow" )
2060+ string_dtype = pd .ArrowDtype (pa .string ())
2061+ else :
2062+ string_dtype = pd .StringDtype (string_storage )
2063+
20852064 expected = DataFrame (
20862065 {
20872066 "a" : Series ([1 , np .nan , 3 ], dtype = "Int64" ),
@@ -2090,12 +2069,13 @@ def test_read_json_dtype_backend(
20902069 "d" : Series ([1.5 , 2.0 , 2.5 ], dtype = "Float64" ),
20912070 "e" : Series ([True , False , NA ], dtype = "boolean" ),
20922071 "f" : Series ([True , False , True ], dtype = "boolean" ),
2093- "g" : string_array ,
2094- "h" : string_array_na ,
2072+ "g" : Series ([ "a" , "b" , "c" ], dtype = string_dtype ) ,
2073+ "h" : Series ([ "a" , "b" , None ], dtype = string_dtype ) ,
20952074 }
20962075 )
20972076
20982077 if dtype_backend == "pyarrow" :
2078+ pa = pytest .importorskip ("pyarrow" )
20992079 from pandas .arrays import ArrowExtensionArray
21002080
21012081 expected = DataFrame (
0 commit comments