Skip to content

BUG: pprint_thing(..., quote_strings=True) fails for strings with embedded single-quotes #60190

Closed
@zpincus

Description

@zpincus

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

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.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions