@@ -554,22 +554,26 @@ def test_usecols_dtype(all_parsers):
554554def test_usecols_order (all_parsers , usecols , usecols_use_order ):
555555 # TODOE add portion in doc for 3.0 transition
556556 parser = all_parsers
557+ pyarrow_flag = False
557558 data = """\
558559 a,b,c,d
5595601,2,3,0
5605614,5,6,0
5615627,8,9,0
56256310,11,12,13"""
563564
564- msg = "The pyarrow engine does not allow 'usecols' to be integer column positions"
565- if parser .engine == "pyarrow" and isinstance (usecols [0 ], int ):
566- with pytest .raises (ValueError , match = msg ):
567- parser .read_csv (StringIO (data ), usecols = usecols )
568- return
569-
570- result = parser .read_csv (StringIO (data ), usecols = usecols )
565+ if parser .engine == "pyarrow" :
566+ if isinstance (usecols [0 ], int ):
567+ msg = "The pyarrow engine does not allow 'usecols' to be integer column"
568+ with pytest .raises (ValueError , match = msg ):
569+ parser .read_csv (StringIO (data ), usecols = usecols )
570+ return
571+ else :
572+ # looks like pyarrow already considers column order by default.
573+ # Modifies test to account for it in selecting expected df
574+ pyarrow_flag = True
571575
572- if usecols_use_order :
576+ if usecols_use_order or pyarrow_flag :
573577 expected = DataFrame (
574578 {"d" : [0 , 0 , 0 , 13 ], "a" : [1 , 4 , 7 , 10 ], "c" : [3 , 6 , 9 , 12 ]}
575579 )
@@ -579,4 +583,5 @@ def test_usecols_order(all_parsers, usecols, usecols_use_order):
579583 )
580584
581585 with option_context ("future.usecols_use_order" , usecols_use_order ):
586+ result = parser .read_csv (StringIO (data ), usecols = usecols )
582587 tm .assert_frame_equal (result , expected )
0 commit comments