Skip to content

Commit

Permalink
BUG: closes issue pandas-dev#7212 - side effect on passed columns list
Browse files Browse the repository at this point in the history
  • Loading branch information
ajamian committed May 23, 2015
1 parent 9b04bd0 commit 7708804
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -3453,6 +3453,10 @@ def get_blk_items(mgr, blocks):
def process_axes(self, obj, columns=None):
""" process axes filters """

# make a copy to avoid side effects
if columns is not None:
columns = list(columns)

# make sure to include levels if we have them
if columns is not None and self.is_multi_index:
for n in self.levels:
Expand Down
19 changes: 19 additions & 0 deletions pandas/io/tests/test_pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -4617,6 +4617,25 @@ def test_preserve_timedeltaindex_type(self):
store['df'] = df
assert_frame_equal(store['df'], df)

def test_colums_multiindex_modified(self):
df = DataFrame(np.random.rand(4, 5),
index=list('abcd'),
columns=list('ABCDE'))
df.index.name = 'letters'
df = df.set_index(keys='E', append=True)

data_columns = df.index.names+df.columns.tolist()
with ensure_clean_path(self.path) as path:
df.to_hdf(path, 'df',
mode='a',
append=True,
data_columns=data_columns,
index=False)
cols2load = list('BCD')
cols2load_original = list(cols2load)
df_loaded = read_hdf(path, 'df', columns=cols2load)
self.assertTrue(cols2load_original == cols2load)


def _test_sort(obj):
if isinstance(obj, DataFrame):
Expand Down

0 comments on commit 7708804

Please sign in to comment.