BUG: pprint_thing(..., quote_strings=True) fails for strings with embedded single-quotes · Issue #60190 · pandas-dev/pandas (original) (raw)

Pandas version checks

Reproducible Example

from pandas.io.formats.printing import pprint_thing

print(pprint_thing("'510", quote_strings=True))

Issue Description

The code above produces the incorrect ''510' as output, instead of "'510" as python does, or even '\'510'.

In the current master the cause is clear enough:

elif isinstance(thing, str) and quote_strings:
    result = f"'{as_escaped_string(thing)}'"

Either python's string repr could be used (assuming the rest of its behavior is fit for the purpose), or single-quotes could be explicitly backslash-escaped.

Expected Behavior

As above.

Installed Versions

As above, but is present in GitHub master as of right now.