|
49 | 49 | is_object_dtype,
|
50 | 50 | is_string_dtype,
|
51 | 51 | )
|
52 |
| -from pandas.core.dtypes.dtypes import ( |
53 |
| - ArrowDtype, |
54 |
| - DatetimeTZDtype, |
55 |
| -) |
| 52 | +from pandas.core.dtypes.dtypes import DatetimeTZDtype |
56 | 53 | from pandas.core.dtypes.missing import isna
|
57 | 54 |
|
58 | 55 | from pandas import get_option
|
|
68 | 65 | from pandas.core.internals.construction import convert_object_array
|
69 | 66 | from pandas.core.tools.datetimes import to_datetime
|
70 | 67 |
|
| 68 | +from pandas.io._util import arrow_table_to_pandas |
| 69 | + |
71 | 70 | if TYPE_CHECKING:
|
72 | 71 | from collections.abc import (
|
73 | 72 | Iterator,
|
@@ -2221,23 +2220,10 @@ def read_table(
|
2221 | 2220 | else:
|
2222 | 2221 | stmt = f"SELECT {select_list} FROM {table_name}"
|
2223 | 2222 |
|
2224 |
| - mapping: type[ArrowDtype] | None | Callable |
2225 |
| - if dtype_backend == "pyarrow": |
2226 |
| - mapping = ArrowDtype |
2227 |
| - elif dtype_backend == "numpy_nullable": |
2228 |
| - from pandas.io._util import _arrow_dtype_mapping |
2229 |
| - |
2230 |
| - mapping = _arrow_dtype_mapping().get |
2231 |
| - elif using_string_dtype(): |
2232 |
| - from pandas.io._util import arrow_string_types_mapper |
2233 |
| - |
2234 |
| - mapping = arrow_string_types_mapper() |
2235 |
| - else: |
2236 |
| - mapping = None |
2237 |
| - |
2238 | 2223 | with self.con.cursor() as cur:
|
2239 | 2224 | cur.execute(stmt)
|
2240 |
| - df = cur.fetch_arrow_table().to_pandas(types_mapper=mapping) |
| 2225 | + pa_table = cur.fetch_arrow_table() |
| 2226 | + df = arrow_table_to_pandas(pa_table, dtype_backend=dtype_backend) |
2241 | 2227 |
|
2242 | 2228 | return _wrap_result_adbc(
|
2243 | 2229 | df,
|
@@ -2305,23 +2291,10 @@ def read_query(
|
2305 | 2291 | if chunksize:
|
2306 | 2292 | raise NotImplementedError("'chunksize' is not implemented for ADBC drivers")
|
2307 | 2293 |
|
2308 |
| - mapping: type[ArrowDtype] | None | Callable |
2309 |
| - if dtype_backend == "pyarrow": |
2310 |
| - mapping = ArrowDtype |
2311 |
| - elif dtype_backend == "numpy_nullable": |
2312 |
| - from pandas.io._util import _arrow_dtype_mapping |
2313 |
| - |
2314 |
| - mapping = _arrow_dtype_mapping().get |
2315 |
| - elif using_string_dtype(): |
2316 |
| - from pandas.io._util import arrow_string_types_mapper |
2317 |
| - |
2318 |
| - mapping = arrow_string_types_mapper() |
2319 |
| - else: |
2320 |
| - mapping = None |
2321 |
| - |
2322 | 2294 | with self.con.cursor() as cur:
|
2323 | 2295 | cur.execute(sql)
|
2324 |
| - df = cur.fetch_arrow_table().to_pandas(types_mapper=mapping) |
| 2296 | + pa_table = cur.fetch_arrow_table() |
| 2297 | + df = arrow_table_to_pandas(pa_table, dtype_backend=dtype_backend) |
2325 | 2298 |
|
2326 | 2299 | return _wrap_result_adbc(
|
2327 | 2300 | df,
|
|
0 commit comments