Skip to content

Commit 001eef2

Browse files
committed
use passed pyarrow dtype when reading json
1 parent 160b3eb commit 001eef2

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

pandas/io/json/_json.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from pandas.core.dtypes.common import (
3333
ensure_str,
3434
is_string_dtype,
35+
pandas_dtype,
3536
)
3637
from pandas.core.dtypes.dtypes import PeriodDtype
3738

@@ -939,7 +940,19 @@ def read(self) -> DataFrame | Series:
939940
with self:
940941
if self.engine == "pyarrow":
941942
pyarrow_json = import_optional_dependency("pyarrow.json")
942-
pa_table = pyarrow_json.read_json(self.data)
943+
if isinstance(self.dtype, dict):
944+
pa = import_optional_dependency("pyarrow")
945+
fields = [
946+
(field, pandas_dtype(dtype).pyarrow_dtype)
947+
for field, dtype in self.dtype.items()
948+
]
949+
schema = pa.schema(fields)
950+
pa_table = pyarrow_json.read_json(
951+
self.data,
952+
parse_options=pyarrow_json.ParseOptions(explicit_schema=schema),
953+
)
954+
else:
955+
pa_table = pyarrow_json.read_json(self.data)
943956

944957
mapping: type[ArrowDtype] | None | Callable
945958
if self.dtype_backend == "pyarrow":

0 commit comments

Comments
 (0)