31
31
read_json ,
32
32
)
33
33
import pandas ._testing as tm
34
- from pandas .core .arrays import (
35
- ArrowStringArray ,
36
- StringArray ,
37
- )
38
- from pandas .core .arrays .string_arrow import ArrowStringArrayNumpySemantics
39
34
40
35
from pandas .io .json import ujson_dumps
41
36
@@ -2037,14 +2032,10 @@ def test_json_uint64(self):
2037
2032
assert result == expected
2038
2033
2039
2034
@pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" , strict = False )
2040
- @pytest .mark .parametrize (
2041
- "orient" , ["split" , "records" , "values" , "index" , "columns" ]
2042
- )
2043
2035
def test_read_json_dtype_backend (
2044
2036
self , string_storage , dtype_backend , orient , using_infer_string
2045
2037
):
2046
2038
# GH#50750
2047
- pa = pytest .importorskip ("pyarrow" )
2048
2039
df = DataFrame (
2049
2040
{
2050
2041
"a" : Series ([1 , np .nan , 3 ], dtype = "Int64" ),
@@ -2058,30 +2049,18 @@ def test_read_json_dtype_backend(
2058
2049
}
2059
2050
)
2060
2051
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
-
2079
2052
out = df .to_json (orient = orient )
2080
2053
with pd .option_context ("mode.string_storage" , string_storage ):
2081
2054
result = read_json (
2082
2055
StringIO (out ), dtype_backend = dtype_backend , orient = orient
2083
2056
)
2084
2057
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
+
2085
2064
expected = DataFrame (
2086
2065
{
2087
2066
"a" : Series ([1 , np .nan , 3 ], dtype = "Int64" ),
@@ -2090,12 +2069,13 @@ def test_read_json_dtype_backend(
2090
2069
"d" : Series ([1.5 , 2.0 , 2.5 ], dtype = "Float64" ),
2091
2070
"e" : Series ([True , False , NA ], dtype = "boolean" ),
2092
2071
"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 ) ,
2095
2074
}
2096
2075
)
2097
2076
2098
2077
if dtype_backend == "pyarrow" :
2078
+ pa = pytest .importorskip ("pyarrow" )
2099
2079
from pandas .arrays import ArrowExtensionArray
2100
2080
2101
2081
expected = DataFrame (
0 commit comments