8000 ENH: Improve error message for empty object array by bashtage · Pull Request #23718 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

ENH: Improve error message for empty object array #23718

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 2 commits into from
Nov 17, 2018
Merged
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
Next Next commit
ENH: Improve error message for empty object array
Improve the error message shown when an object array is empty

closes #23572
  • Loading branch information
bashtage committed Nov 15, 2018
commit 904576a30efc4eca5691f9313b2c35e188ee6509
7 changes: 6 additions & 1 deletion pandas/io/stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1868,7 +1868,12 @@ def _dtype_to_default_stata_fmt(dtype, column, dta_version=114,
inferred_dtype = infer_dtype(column.dropna())
if not (inferred_dtype in ('string', 'unicode') or
len(column) == 0):
raise ValueError('Writing general object arrays is not supported')
raise ValueError('Only string-like object arrays containing all '
'strings or a mix of strings and None can be '
'exported. Object arrays containing only null '
'values are prohibited. Other object types'
'cannot be exported and must first be converted '
'to one of the supported types.')
Copy link
Member
@gfyoung gfyoung Nov 15, 2018

Choose a reason for hiding this comment

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

  • By one of the supported types, do you just mean string?
  • Given that you didn't check the box yet in the PR, I presume a test for this error message is coming as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a test, for good measure

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By one of the supported types, do you just mean string?

It could be any supported type, int8-32, float, double, string or datetime. The user has to make a choice as to what best expresses the object.

itemsize = max_len_string_array(ensure_object(column.values))
if itemsize > max_str_len:
if dta_version >= 117:
Expand Down
0