Skip to content

Commit

Permalink
[Backport #14791] BUG: multi-index HDFStore data_columns=True
Browse files Browse the repository at this point in the history
closes #14435

Author: Chris <cbartak@gmail.com>

Closes #14791 from chris-b1/hdf-mi-datacolumns and squashes the following commits:

5d32610 [Chris] BUG: multi-index HDFStore data_columns=True

(cherry picked from commit 27fcd81)
  • Loading branch information
chris-b1 authored and jorisvandenbossche committed Dec 15, 2016
1 parent 95f088f commit 7814a66
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.19.2.txt
Expand Up @@ -58,7 +58,7 @@ Bug Fixes




- Bug ``HDFStore`` writing a ``MultiIndex`` when using ``data_columns=True`` (:issue:`14435`)


- Bug in clipboard functions on linux with python2 with unicode and separators (:issue:`13747`)
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/pytables.py
Expand Up @@ -4254,7 +4254,7 @@ def write(self, obj, data_columns=None, **kwargs):
if data_columns is None:
data_columns = []
elif data_columns is True:
data_columns = obj.columns[:]
data_columns = obj.columns.tolist()
obj, self.levels = self.validate_multiindex(obj)
for n in self.levels:
if n not in data_columns:
Expand Down
13 changes: 13 additions & 0 deletions pandas/io/tests/test_pytables.py
Expand Up @@ -1818,6 +1818,19 @@ def test_select_columns_in_where(self):
store.put('s', s, format='table')
tm.assert_series_equal(store.select('s', where="columns=['A']"), s)

def test_mi_data_columns(self):
# GH 14435
idx = pd.MultiIndex.from_arrays([date_range('2000-01-01', periods=5),
range(5)], names=['date', 'id'])
df = pd.DataFrame({'a': [1.1, 1.2, 1.3, 1.4, 1.5]}, index=idx)

with ensure_clean_store(self.path) as store:
store.append('df', df, data_columns=True)

actual = store.select('df', where='id == 1')
expected = df.iloc[[1], :]
tm.assert_frame_equal(actual, expected)

def test_pass_spec_to_storer(self):

df = tm.makeDataFrame()
Expand Down

0 comments on commit 7814a66

Please sign in to comment.