File tree 3 files changed +29
-0
lines changed
3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,8 @@ Performance Improvements
60
60
Bug Fixes
61
61
~~~~~~~~~
62
62
63
+ - Bug where read_hdf store.select modifies the passed columns list when
64
+ multi-indexed (:issue:`7212`)
63
65
- Bug in ``Categorical`` repr with ``display.width`` of ``None`` in Python 3 (:issue:`10087`)
64
66
65
67
Original file line number Diff line number Diff line change @@ -3453,6 +3453,10 @@ def get_blk_items(mgr, blocks):
3453
3453
def process_axes (self , obj , columns = None ):
3454
3454
""" process axes filters """
3455
3455
3456
+ # make a copy to avoid side effects
3457
+ if columns is not None :
3458
+ columns = list (columns )
3459
+
3456
3460
# make sure to include levels if we have them
3457
3461
if columns is not None and self .is_multi_index :
3458
3462
for n in self .levels :
Original file line number Diff line number Diff line change @@ -4617,6 +4617,29 @@ def test_preserve_timedeltaindex_type(self):
4617
4617
store ['df' ] = df
4618
4618
assert_frame_equal (store ['df' ], df )
4619
4619
4620
+ def test_colums_multiindex_modified (self ):
4621
+ # BUG: 7212
4622
+ # read_hdf store.select modified the passed columns parameters
4623
+ # when multi-indexed.
4624
+
4625
+ df = DataFrame (np .random .rand (4 , 5 ),
4626
+ index = list ('abcd' ),
4627
+ columns = list ('ABCDE' ))
4628
+ df .index .name = 'letters'
4629
+ df = df .set_index (keys = 'E' , append = True )
4630
+
4631
+ data_columns = df .index .names + df .columns .tolist ()
4632
+ with ensure_clean_path (self .path ) as path :
4633
+ df .to_hdf (path , 'df' ,
4634
+ mode = 'a' ,
4635
+ append = True ,
4636
+ data_columns = data_columns ,
4637
+ index = False )
4638
+ cols2load = list ('BCD' )
4639
+ cols2load_original = list (cols2load )
4640
+ df_loaded = read_hdf (path , 'df' , columns = cols2load )
4641
+ self .assertTrue (cols2load_original == cols2load )
4642
+
4620
4643
4621
4644
def _test_sort (obj ):
4622
4645
if isinstance (obj , DataFrame ):
You can’t perform that action at this time.
0 commit comments