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 all 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 @@ -68,6 +68,7 @@ Other enhancements
- :meth:`Series.map` can now accept kwargs to pass on to func (:issue:`59814`)
- :meth:`Series.str.get_dummies` now accepts a ``dtype`` parameter to specify the dtype of the resulting DataFrame (:issue:`47872`)
- :meth:`pandas.concat` will raise a ``ValueError`` when ``ignore_index=True`` and ``keys`` is not ``None`` (:issue:`59274`)
- :py:class:`frozenset` elements in pandas objects are now natively printed (:issue:`60690`)
- Implemented :meth:`Series.str.isascii` and :meth:`Series.str.isascii` (:issue:`59091`)
- Multiplying two :class:`DateOffset` objects will now raise a ``TypeError`` instead of a ``RecursionError`` (:issue:`59442`)
- Restore support for reading Stata 104-format and enable reading 103-format dta files (:issue:`58554`)
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