Skip to content

Commit 9c3a2fb

Browse files
committed
Added a helper function to help the date column dtype be customized
1 parent 139def2 commit 9c3a2fb

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pandas/io/parsers/arrow_parser_wrapper.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,25 @@ def read(self) -> DataFrame:
306306

307307
else:
308308
frame = table.to_pandas()
309+
310+
self._set_date_column_dtype(frame, date_columns=["date_column1", "date_column2"], dtype="timestamp[ns][pyarrow]")
311+
309312
return self._finalize_pandas_output(frame)
313+
314+
315+
def _set_date_column_dtype(self, frame: DataFrame, date_columns: list, dtype: str):
316+
"""
317+
Sets the dtype for specified date columns in the DataFrame.
318+
319+
Parameters
320+
----------
321+
frame : DataFrame
322+
The DataFrame to modify.
323+
date_columns : list
324+
List of column names that are date columns.
325+
dtype : str
326+
The dtype to apply to these columns, e.g., 'datetime64[ns]'.
327+
"""
328+
for col in date_columns:
329+
if col in frame.columns:
330+
frame[col] = frame[col].astype(dtype)

0 commit comments

Comments
 (0)