Skip to content

BUG: pretty print all Mappings, not just dicts#57915

Merged
mroeschke merged 1 commit intopandas-dev:mainfrom
NickCrews:pprint-mapping
Mar 20, 2024
Merged

BUG: pretty print all Mappings, not just dicts#57915
mroeschke merged 1 commit intopandas-dev:mainfrom
NickCrews:pprint-mapping

Conversation

@NickCrews
Copy link
Copy Markdown
Contributor

@NickCrews NickCrews commented Mar 19, 2024

This was discovered in ibis-project/ibis#8687

Due to a strict isinstance(x, dict) check, custom mapping types would instead get treated as mere iterables, so only the keys would get printed as a tuple:

import pandas as pd
from ibis.common.collections import frozendict
pd.Series([frozendict({"a": 5, "b": 6})])
# 0    (a, b)
# dtype: object

@mroeschke mroeschke added the Output-Formatting __repr__ of pandas objects, to_string label Mar 19, 2024
Copy link
Copy Markdown
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

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

I think this would be OK. Could you come up with a test?

@NickCrews
Copy link
Copy Markdown
Contributor Author

that was a pretty nice experience setting up a dev environment locally, pass along my compliments to the rest of the pandas maintainers @mroeschke !

Comment thread pandas/io/formats/printing.py
Copy link
Copy Markdown
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

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

Could you also add a whatsnew note in v3.0.0.rst?

@mroeschke mroeschke added this to the 3.0 milestone Mar 19, 2024
@mroeschke mroeschke merged commit 924f246 into pandas-dev:main Mar 20, 2024
@mroeschke
Copy link
Copy Markdown
Member

Thanks @NickCrews

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

Successfully merging this pull request may close these issues.

2 participants