Skip to content

Commit 5d32610

Browse files
committed
BUG: multi-index HDFStore data_columns=True
1 parent 725453d commit 5d32610

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

doc/source/whatsnew/v0.19.2.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Bug Fixes
5858

5959

6060

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

6363

6464
- Bug in clipboard functions on linux with python2 with unicode and separators (:issue:`13747`)

pandas/io/pytables.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4254,7 +4254,7 @@ def write(self, obj, data_columns=None, **kwargs):
42544254
if data_columns is None:
42554255
data_columns = []
42564256
elif data_columns is True:
4257-
data_columns = obj.columns[:]
4257+
data_columns = obj.columns.tolist()
42584258
obj, self.levels = self.validate_multiindex(obj)
42594259
for n in self.levels:
42604260
if n not in data_columns:

pandas/io/tests/test_pytables.py

+13
Original file line numberDiff line numberDiff line change
@@ -1818,6 +1818,19 @@ def test_select_columns_in_where(self):
18181818
store.put('s', s, format='table')
18191819
tm.assert_series_equal(store.select('s', where="columns=['A']"), s)
18201820

1821+
def test_mi_data_columns(self):
1822+
# GH 14435
1823+
idx = pd.MultiIndex.from_arrays([date_range('2000-01-01', periods=5),
1824+
range(5)], names=['date', 'id'])
1825+
df = pd.DataFrame({'a': [1.1, 1.2, 1.3, 1.4, 1.5]}, index=idx)
1826+
1827+
with ensure_clean_store(self.path) as store:
1828+
store.append('df', df, data_columns=True)
1829+
1830+
actual = store.select('df', where='id == 1')
1831+
expected = df.iloc[[1], :]
1832+
tm.assert_frame_equal(actual, expected)
1833+
18211834
def test_pass_spec_to_storer(self):
18221835

18231836
df = tm.makeDataFrame()

0 commit comments

Comments
 (0)