Skip to content
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

More helpful Stata object dtype error. (#23572) #23646

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 7 additions & 1 deletion pandas/io/stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,12 @@ def parse_dates_safe(dates, delta=False, year=False, days=False):
"""


general_object_array_error = """
Writing non-string object columns is not supported. Column '%s' does not
Copy link
Contributor

Choose a reason for hiding this comment

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

We've been moving to new-style format strings. Could you change the %s to {}?

Also for relatively simply error message like this, having the message next to where it's raised helps keep the code clearer. Could you define this message where it's used? Use params to wrap lines in the source

msg = (
    "Writing non-string... "
    " ... "
)
raise ValueError(msg)

satisfy this restriction.
"""


class PossiblePrecisionLoss(Warning):
pass

Expand Down Expand Up @@ -1868,7 +1874,7 @@ 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(general_object_array_error % column.name)
itemsize = max_len_string_array(ensure_object(column.values))
if itemsize > max_str_len:
if dta_version >= 117:
Expand Down