28
28
read_json ,
29
29
)
30
30
import pandas ._testing as tm
31
- from pandas .core .arrays import (
32
- ArrowStringArray ,
33
- StringArray ,
34
- )
35
- from pandas .core .arrays .string_arrow import ArrowStringArrayNumpySemantics
36
31
37
32
from pandas .io .json import ujson_dumps
38
33
@@ -2143,12 +2138,10 @@ def test_json_uint64(self):
2143
2138
result = df .to_json (orient = "split" )
2144
2139
assert result == expected
2145
2140
2146
- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" , strict = False )
2147
2141
def test_read_json_dtype_backend (
2148
2142
self , string_storage , dtype_backend , orient , using_infer_string
2149
2143
):
2150
2144
# GH#50750
2151
- pa = pytest .importorskip ("pyarrow" )
2152
2145
df = DataFrame (
2153
2146
{
2154
2147
"a" : Series ([1 , np .nan , 3 ], dtype = "Int64" ),
@@ -2162,30 +2155,18 @@ def test_read_json_dtype_backend(
2162
2155
}
2163
2156
)
2164
2157
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
-
2183
2158
out = df .to_json (orient = orient )
2184
2159
with pd .option_context ("mode.string_storage" , string_storage ):
2185
2160
result = read_json (
2186
2161
StringIO (out ), dtype_backend = dtype_backend , orient = orient
2187
2162
)
2188
2163
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
+
2189
2170
expected = DataFrame (
2190
2171
{
2191
2172
"a" : Series ([1 , np .nan , 3 ], dtype = "Int64" ),
@@ -2194,12 +2175,13 @@ def test_read_json_dtype_backend(
2194
2175
"d" : Series ([1.5 , 2.0 , 2.5 ], dtype = "Float64" ),
2195
2176
"e" : Series ([True , False , NA ], dtype = "boolean" ),
2196
2177
"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 ) ,
2199
2180
}
2200
2181
)
2201
2182
2202
2183
if dtype_backend == "pyarrow" :
2184
+ pa = pytest .importorskip ("pyarrow" )
2203
2185
from pandas .arrays import ArrowExtensionArray
2204
2186
2205
2187
expected = DataFrame (
0 commit comments