|
48 | 48 | is_object_dtype, |
49 | 49 | is_string_dtype, |
50 | 50 | ) |
51 | | -from pandas.core.dtypes.dtypes import ( |
52 | | - ArrowDtype, |
53 | | - DatetimeTZDtype, |
54 | | -) |
| 51 | +from pandas.core.dtypes.dtypes import DatetimeTZDtype |
55 | 52 | from pandas.core.dtypes.missing import isna |
56 | 53 |
|
57 | 54 | from pandas import get_option |
|
67 | 64 | from pandas.core.internals.construction import convert_object_array |
68 | 65 | from pandas.core.tools.datetimes import to_datetime |
69 | 66 |
|
| 67 | +from pandas.io._util import arrow_table_to_pandas |
| 68 | + |
70 | 69 | if TYPE_CHECKING: |
71 | 70 | from collections.abc import ( |
72 | 71 | Callable, |
@@ -2208,23 +2207,10 @@ def read_table( |
2208 | 2207 | else: |
2209 | 2208 | stmt = f"SELECT {select_list} FROM {table_name}" |
2210 | 2209 |
|
2211 | | - mapping: type[ArrowDtype] | None | Callable |
2212 | | - if dtype_backend == "pyarrow": |
2213 | | - mapping = ArrowDtype |
2214 | | - elif dtype_backend == "numpy_nullable": |
2215 | | - from pandas.io._util import _arrow_dtype_mapping |
2216 | | - |
2217 | | - mapping = _arrow_dtype_mapping().get |
2218 | | - elif using_string_dtype(): |
2219 | | - from pandas.io._util import arrow_string_types_mapper |
2220 | | - |
2221 | | - mapping = arrow_string_types_mapper() |
2222 | | - else: |
2223 | | - mapping = None |
2224 | | - |
2225 | 2210 | with self.con.cursor() as cur: |
2226 | 2211 | cur.execute(stmt) |
2227 | | - df = cur.fetch_arrow_table().to_pandas(types_mapper=mapping) |
| 2212 | + pa_table = cur.fetch_arrow_table() |
| 2213 | + df = arrow_table_to_pandas(pa_table, dtype_backend=dtype_backend) |
2228 | 2214 |
|
2229 | 2215 | return _wrap_result_adbc( |
2230 | 2216 | df, |
@@ -2292,23 +2278,10 @@ def read_query( |
2292 | 2278 | if chunksize: |
2293 | 2279 | raise NotImplementedError("'chunksize' is not implemented for ADBC drivers") |
2294 | 2280 |
|
2295 | | - mapping: type[ArrowDtype] | None | Callable |
2296 | | - if dtype_backend == "pyarrow": |
2297 | | - mapping = ArrowDtype |
2298 | | - elif dtype_backend == "numpy_nullable": |
2299 | | - from pandas.io._util import _arrow_dtype_mapping |
2300 | | - |
2301 | | - mapping = _arrow_dtype_mapping().get |
2302 | | - elif using_string_dtype(): |
2303 | | - from pandas.io._util import arrow_string_types_mapper |
2304 | | - |
2305 | | - mapping = arrow_string_types_mapper() |
2306 | | - else: |
2307 | | - mapping = None |
2308 | | - |
2309 | 2281 | with self.con.cursor() as cur: |
2310 | 2282 | cur.execute(sql) |
2311 | | - df = cur.fetch_arrow_table().to_pandas(types_mapper=mapping) |
| 2283 | + pa_table = cur.fetch_arrow_table() |
| 2284 | + df = arrow_table_to_pandas(pa_table, dtype_backend=dtype_backend) |
2312 | 2285 |
|
2313 | 2286 | return _wrap_result_adbc( |
2314 | 2287 | df, |
|
0 commit comments