|
42 | 42 | from pandas.compat._optional import import_optional_dependency |
43 | 43 | from pandas.errors import AbstractMethodError |
44 | 44 | from pandas.util._decorators import doc |
| 45 | +from pandas.util._validators import check_dtype_backend |
45 | 46 |
|
46 | 47 | from pandas.core.dtypes.common import ( |
47 | 48 | ensure_str, |
@@ -744,6 +745,8 @@ def read_json( |
744 | 745 | if orient == "table" and convert_axes: |
745 | 746 | raise ValueError("cannot pass both convert_axes and orient='table'") |
746 | 747 |
|
| 748 | + check_dtype_backend(dtype_backend) |
| 749 | + |
747 | 750 | if dtype is None and orient != "table": |
748 | 751 | # error: Incompatible types in assignment (expression has type "bool", variable |
749 | 752 | # has type "Union[ExtensionDtype, str, dtype[Any], Type[str], Type[float], |
@@ -944,14 +947,18 @@ def read(self) -> DataFrame | Series: |
944 | 947 | if self.engine == "pyarrow": |
945 | 948 | pyarrow_json = import_optional_dependency("pyarrow.json") |
946 | 949 | pa_table = pyarrow_json.read_json(self.data) |
| 950 | + |
| 951 | + mapping: type[ArrowDtype] | None | Callable |
947 | 952 | if self.dtype_backend == "pyarrow": |
948 | | - return pa_table.to_pandas(types_mapper=ArrowDtype) |
| 953 | + mapping = ArrowDtype |
949 | 954 | elif self.dtype_backend == "numpy_nullable": |
950 | 955 | from pandas.io._util import _arrow_dtype_mapping |
951 | 956 |
|
952 | | - mapping = _arrow_dtype_mapping() |
953 | | - return pa_table.to_pandas(types_mapper=mapping.get) |
954 | | - return pa_table.to_pandas() |
| 957 | + mapping = _arrow_dtype_mapping().get |
| 958 | + else: |
| 959 | + mapping = None |
| 960 | + |
| 961 | + return pa_table.to_pandas(types_mapper=mapping) |
955 | 962 | elif self.engine == "ujson": |
956 | 963 | if self.lines: |
957 | 964 | if self.chunksize: |
|
0 commit comments