File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -468,11 +468,17 @@ def pyarrow_types_from_pandas( # pylint: disable=too-many-branches
468
468
indexes : List [str ] = []
469
469
if index is True :
470
470
# Get index columns
471
- # Adding indexes as columns via .reset_index() because
472
- # pa.Schema.from_pandas(.., preserve_index=True) fails with
473
- # "'Index' object has no attribute 'head'" if using extension
474
- # dtypes on pandas 1.4.x
475
- fields = pa .Schema .from_pandas (df = df [[]].reset_index (), preserve_index = False )
471
+ try :
472
+ fields = pa .Schema .from_pandas (df = df [[]], preserve_index = True )
473
+ except AttributeError as ae :
474
+ if "'Index' object has no attribute 'head'" not in str (ae ):
475
+ raise ae
476
+ # Get index fields from a new df with only index columns
477
+ # Adding indexes as columns via .reset_index() because
478
+ # pa.Schema.from_pandas(.., preserve_index=True) fails with
479
+ # "'Index' object has no attribute 'head'" if using extension
480
+ # dtypes on pandas 1.4.x
481
+ fields = pa .Schema .from_pandas (df = df .reset_index ().drop (columns = cols ), preserve_index = False )
476
482
for field in fields :
477
483
name = str (field .name )
478
484
_logger .debug ("Inferring PyArrow type from index: %s" , name )
You can’t perform that action at this time.
0 commit comments