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

EHN: handle frozenset in pprint #60828

Merged
merged 5 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Other enhancements
- Support passing a :class:`Iterable[Hashable]` input to :meth:`DataFrame.drop_duplicates` (:issue:`59237`)
- Support reading Stata 102-format (Stata 1) dta files (:issue:`58978`)
- Support reading Stata 110-format (Stata 7) dta files (:issue:`47176`)
- ``frozenset`` are now pretty printted (:issue:`60690`)
quangngd marked this conversation as resolved.
Show resolved Hide resolved

.. ---------------------------------------------------------------------------
.. _whatsnew_300.notable_bug_fixes:
Expand Down
2 changes: 2 additions & 0 deletions pandas/io/formats/printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ def _pprint_seq(
"""
if isinstance(seq, set):
fmt = "{{{body}}}"
elif isinstance(seq, frozenset):
fmt = "frozenset({body})"
else:
fmt = "[{body}]" if hasattr(seq, "__setitem__") else "({body})"

Expand Down
3 changes: 3 additions & 0 deletions pandas/tests/io/formats/test_printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ def test_repr_dict(self):
def test_repr_mapping(self):
assert printing.pprint_thing(MyMapping()) == "{'a': 4, 'b': 4}"

def test_repr_frozenset(self):
assert printing.pprint_thing(frozenset([1, 2])) == "frozenset(1, 2)"
Copy link
Contributor

@wjandrea wjandrea Feb 6, 2025

Choose a reason for hiding this comment

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

The output should have braces: frozenset({1, 2})

Copy link
Contributor

Choose a reason for hiding this comment

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

I opened #60867



class TestFormatBase:
def test_adjoin(self):
Expand Down
Loading