File tree Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Original file line number Diff line number Diff line change @@ -467,13 +467,12 @@ def pyarrow_types_from_pandas( # pylint: disable=too-many-branches
467
467
# Filling indexes
468
468
indexes : List [str ] = []
469
469
if index is True :
470
- try :
471
- fields = pa .Schema .from_pandas (df = df [[]], preserve_index = True )
472
- except AttributeError as ae :
473
- if "'Index' object has no attribute 'head'" not in str (ae ):
474
- raise ae
475
- # Get index fields from a new df with only index columns
476
- fields = pa .Schema .from_pandas (df = df .reset_index ().drop (columns = cols ), preserve_index = False )
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 )
477
476
for field in fields :
478
477
name = str (field .name )
479
478
_logger .debug ("Inferring PyArrow type from index: %s" , name )
You can’t perform that action at this time.
0 commit comments