Skip to content

Commit d2925bc

Browse files
committed
use native to_pyarrow_type
1 parent df9e96d commit d2925bc

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

pandas/io/parsers/arrow_parser_wrapper.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
)
2020
from pandas.core.dtypes.inference import is_integer
2121

22+
from pandas.core.arrays.arrow.array import to_pyarrow_type
23+
2224
from pandas.io._util import arrow_table_to_pandas
2325
from pandas.io.parsers.base_parser import ParserBase
2426

@@ -145,20 +147,18 @@ def handle_warning(invalid_row) -> str:
145147
if isinstance(self.dtype, dict):
146148
column_types = {}
147149
for col, col_dtype in self.dtype.items():
148-
# TODO: Category dtypes are not currently handled - may cause issues
149-
# with categorical data preservation in pyarrow engine
150-
if col_dtype == "category":
151-
continue
150+
source_dtype = pandas_dtype(col_dtype)
152151

153152
try:
154-
numpy_dtype = pandas_dtype(col_dtype).type
155-
pyarrow_dtype = pa.from_numpy_dtype(numpy_dtype)
156-
column_types[col] = pyarrow_dtype
157-
except (ValueError, pa.ArrowNotImplementedError):
153+
target_dtype = to_pyarrow_type(source_dtype)
154+
if target_dtype:
155+
column_types[col] = target_dtype
156+
157+
except TypeError:
158158
# TODO: Unsupported dtypes silently ignored - may cause
159159
# unexpected behavior when pyarrow applies default inference
160160
# instead of user's dtype
161-
continue
161+
pass
162162

163163
if column_types:
164164
self.convert_options["column_types"] = column_types

0 commit comments

Comments
 (0)