-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
PERF: Improve performance for arrow engine and dtype_backend=pyarrow for datetime conversion #52548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
c048abf
30cf277
789a3cf
fc86c59
c97b8c5
a40f459
f71c512
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ | |
) | ||
from pandas.core.dtypes.missing import isna | ||
|
||
import pandas as pd | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Can we just import There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
from pandas import ( | ||
DatetimeIndex, | ||
StringDtype, | ||
|
@@ -867,6 +868,7 @@ def _do_date_conversions( | |
self.index_names, | ||
names, | ||
keep_date_col=self.keep_date_col, | ||
dtype_backend=self.dtype_backend, | ||
) | ||
|
||
return names, data | ||
|
@@ -1203,6 +1205,7 @@ def _process_date_conversion( | |
index_names, | ||
columns, | ||
keep_date_col: bool = False, | ||
dtype_backend=lib.no_default, | ||
): | ||
def _isindex(colspec): | ||
return (isinstance(index_col, list) and colspec in index_col) or ( | ||
|
@@ -1228,6 +1231,15 @@ def _isindex(colspec): | |
colspec = orig_names[colspec] | ||
if _isindex(colspec): | ||
continue | ||
elif dtype_backend == "pyarrow": | ||
import pyarrow as pa | ||
|
||
dtype = data_dict[colspec].dtype | ||
if isinstance(dtype, pd.ArrowDtype) and pa.types.is_timestamp( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might make sense to keep date types too i.e. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
dtype.pyarrow_dtype | ||
): | ||
continue | ||
|
||
# Pyarrow engine returns Series which we need to convert to | ||
# numpy array before converter, its a no-op for other parsers | ||
data_dict[colspec] = converter( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you fuse this benchmark with
ReadCSVParseDates
above?(You might have to disable
time_multiple_dates
for the pyarrow engine)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer keeping them separate for now since I am expecting to add more arrow versions that aren't really compatible with the others.