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

_pprint_dict forces dictionary-style output for objects that inherit from dict #3251

Closed
rcarneva opened this issue Apr 3, 2013 · 2 comments
Labels
Output-Formatting __repr__ of pandas objects, to_string
Milestone

Comments

@rcarneva
Copy link
Contributor

rcarneva commented Apr 3, 2013

Because pprint_thing checks isinstance(thing, dict), it also catches objects that inherit from dict and forces them to print in the {'a':1, ... } format regardless of the object's unicode, str, or repr definitions. On my machine, I've changed the _pprint_dict function to just:

return unicode(seq)

which seems to give the behavior I'm looking for. I see pprint_thing warns against unicode(object) in general due to nested sequences, but since _pprint_dict doesn't do anything with _nest_lvl anyway, I figured it was probably safe.

@ghost
Copy link

ghost commented Apr 3, 2013

Allowing proper subclasses of Dict/OrderedDict to format themselves
sounds like a reasonable expectation to me.

I'll have to think this over a bit for corner cases, and the code to do it
looks a little fragile.

pprint_dict should call pprint_thing rather then directly calling repr, and use
nest_lvl when doing it, thanks for the catch.

@ghost
Copy link

ghost commented Jan 3, 2014

actually on this one you were right, see closed PR.

@ghost ghost closed this as completed Jan 3, 2014
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

No branches or pull requests

2 participants