Skip to content

Hdffixes #12248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed

Hdffixes #12248

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/source/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2808,8 +2808,8 @@ Storing Mixed Types in a Table
++++++++++++++++++++++++++++++

Storing mixed-dtype data is supported. Strings are stored as a
fixed-width using the maximum size of the appended column. Subsequent
appends will truncate strings at this length.
fixed-width using the maximum size of the appended column. Subsequent attempts
at appending longer strings will raise a ``ValueError``.

Passing ``min_itemsize={`values`: size}`` as a parameter to append
will set a larger minimum for the string columns. Storing ``floats,
Expand Down
9 changes: 6 additions & 3 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,9 @@ def keys(self):
"""
return [n._v_pathname for n in self.groups()]

def __iter__(self):
return iter(self.keys())

def items(self):
"""
iterate on key->group
Expand Down Expand Up @@ -3247,7 +3250,7 @@ def validate_data_columns(self, data_columns, min_itemsize):
# evaluate the passed data_columns, True == use all columns
# take only valide axis labels
if data_columns is True:
data_columns = axis_labels
data_columns = list(axis_labels)
elif data_columns is None:
data_columns = []

Expand Down Expand Up @@ -4084,7 +4087,7 @@ def write(self, obj, data_columns=None, **kwargs):
obj = DataFrame({name: obj}, index=obj.index)
obj.columns = [name]
return super(AppendableSeriesTable, self).write(
obj=obj, data_columns=obj.columns, **kwargs)
obj=obj, data_columns=list(obj.columns), **kwargs)

def read(self, columns=None, **kwargs):

Expand Down Expand Up @@ -4185,7 +4188,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 = list(obj.columns[:])
obj, self.levels = self.validate_multiindex(obj)
for n in self.levels:
if n not in data_columns:
Expand Down
15 changes: 13 additions & 2 deletions pandas/io/tests/test_pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,9 @@ def test_keys(self):
store['d'] = tm.makePanel()
store['foo/bar'] = tm.makePanel()
self.assertEqual(len(store), 5)
self.assertTrue(set(
store.keys()) == set(['/a', '/b', '/c', '/d', '/foo/bar']))
expected = set(['/a', '/b', '/c', '/d', '/foo/bar'])
self.assertTrue(set(store.keys()) == expected)
self.assertTrue(set(store) == expected)

def test_repr(self):

Expand Down Expand Up @@ -1338,6 +1339,16 @@ def check_col(key, name, size):
[[124, 'abcdefqhij'], [346, 'abcdefghijklmnopqrtsuvwxyz']])
self.assertRaises(ValueError, store.append, 'df_new', df_new)

# min_itemsize on Series with Multiindex (GH 10381)
df = tm.makeMixedDataFrame().set_index(['A', 'C'])
store.append('ss', df['B'], min_itemsize={'index': 4})
tm.assert_series_equal(store.select('ss'), df['B'])

# min_itemsize with MultiIndex and data_columns=True
store.append('midf', df, data_columns=True,
min_itemsize={'index': 4})
tm.assert_frame_equal(store.select('midf'), df)

# with nans
_maybe_remove(store, 'df')
df = tm.makeTimeDataFrame()
Expand Down