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