Skip to content

Commit f0a90f2

Browse files
committed
add test case for read_json with explicit pyarrow dtype
1 parent 001eef2 commit f0a90f2

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

pandas/tests/io/json/test_pandas.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import pandas as pd
1919
from pandas import (
2020
NA,
21+
ArrowDtype,
2122
DataFrame,
2223
DatetimeIndex,
2324
Index,
@@ -2163,7 +2164,7 @@ def test_read_json_dtype_backend(
21632164

21642165
if dtype_backend == "pyarrow":
21652166
pa = pytest.importorskip("pyarrow")
2166-
string_dtype = pd.ArrowDtype(pa.string())
2167+
string_dtype = ArrowDtype(pa.string())
21672168
else:
21682169
string_dtype = pd.StringDtype(string_storage)
21692170

@@ -2286,3 +2287,25 @@ def test_read_json_lines_rangeindex():
22862287
result = read_json(StringIO(data), lines=True).index
22872288
expected = RangeIndex(2)
22882289
tm.assert_index_equal(result, expected, exact=True)
2290+
2291+
2292+
def test_read_json_pyarrow_dtype(datapath):
2293+
dtype = {"a": "int32[pyarrow]", "b": "int64[pyarrow]"}
2294+
2295+
df = read_json(
2296+
datapath("io", "json", "data", "line_delimited.json"),
2297+
dtype=dtype,
2298+
lines=True,
2299+
engine="pyarrow",
2300+
dtype_backend="pyarrow",
2301+
)
2302+
2303+
result = df.dtypes
2304+
expected = Series(
2305+
[
2306+
ArrowDtype.construct_from_string("int32[pyarrow]"),
2307+
ArrowDtype.construct_from_string("int64[pyarrow]"),
2308+
],
2309+
index=["a", "b"],
2310+
)
2311+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)