Skip to content

BUG: fix HDFStore.append with all empty strings error (GH12242) #23435

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

Merged
merged 3 commits into from
Nov 1, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,7 @@ Notice how we now instead output ``np.nan`` itself instead of a stringified form
- :func:`read_sas()` will correctly parse sas7bdat files with data page types having also bit 7 set (so page type is 128 + 256 = 384) (:issue:`16615`)
- Bug in :meth:`detect_client_encoding` where potential ``IOError`` goes unhandled when importing in a mod_wsgi process due to restricted access to stdout. (:issue:`21552`)
- Bug in :func:`to_string()` that broke column alignment when ``index=False`` and width of first column's values is greater than the width of first column's header (:issue:`16839`, :issue:`13032`)
- Bug in :meth:`HDFStore.append` when appending a :class:`DataFrame` with an empty string column and min_itemsize < 8 (:issue:`12242`)
Copy link
Member

@gfyoung gfyoung Oct 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double backticks around min_itemsize


Plotting
^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -4637,7 +4637,7 @@ def _convert_string_array(data, encoding, errors, itemsize=None):
# create the sized dtype
if itemsize is None:
ensured = ensure_object(data.ravel())
itemsize = libwriters.max_len_string_array(ensured)
itemsize = max(1, libwriters.max_len_string_array(ensured))

data = np.asarray(data, dtype="S%d" % itemsize)
return data
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/io/test_pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,15 @@ def check_col(key, name, size):
result = store.select('df')
tm.assert_frame_equal(result, df)

# with all empty strings (GH 12242)
_maybe_remove(store, 'df')
df1 = DataFrame({'x': list('abcdef')})
df2 = DataFrame({'x': ['']})
store.append('df', df1, min_itemsize={'x': 1})
store.append('df', df2, min_itemsize={'x': 1})
tm.assert_frame_equal(store.select('df'),
pd.concat([df1, df2]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of comparing to pd.concat. Can you explicitly construct the DataFrame?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you push this to a new test, the existing ones are really long already


with ensure_clean_store(self.path) as store:

def check_col(key, name, size):
Expand Down