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

Better GroupBy dunder str/repr/ipython methods #560

Merged
merged 10 commits into from
Feb 22, 2024

Conversation

jdegenstein
Copy link
Collaborator

Currently when running in an ipython console:

from build123d import *
nonagon = RegularPolygon(5, 9)
print(str(nonagon.edges().group_by(Axis.X)))
print(repr(nonagon.edges().group_by(Axis.X)))
nonagon.edges().group_by(Axis.X)

Returns a not-so-useful result that doesn't give an idea of the structure of the objects inside:

<build123d.topology.GroupBy object at 0x000002AE7995C850>
<build123d.topology.GroupBy object at 0x000002AE79E3D6D0>
Out[1]: <build123d.topology.GroupBy at 0x2ae77a2c0d0>

This PR changes the behavior to the following by using ipython pretty printing:

[[<build123d.topology.Edge at 0x1e32f0c9c50>],
 [<build123d.topology.Edge at 0x1e32f0cae90>,
  <build123d.topology.Edge at 0x1e32febbb50>],
 [<build123d.topology.Edge at 0x1e32fe00050>,
  <build123d.topology.Edge at 0x1e32febbed0>],
 [<build123d.topology.Edge at 0x1e316c2b310>,
  <build123d.topology.Edge at 0x1e32f101410>],
 [<build123d.topology.Edge at 0x1e32f8612d0>,
  <build123d.topology.Edge at 0x1e315962650>]]
[[<build123d.topology.Edge object at 0x000001E3158BDED0>], [<build123d.topology.Edge object at 0x000001E32F891110>, <build123d.topology.Edge object at 0x000001E32F74BE10>], [<build123d.topology.Edge object at 0x000001E32F101410>, <build123d.topology.Edge object at 0x000001E32F08FED0>], [<build123d.topology.Edge object at 0x000001E316C2B310>, <build123d.topology.Edge object at 0x000001E316B55390>], [<build123d.topology.Edge object at 0x000001E32EC0DC50>, <build123d.topology.Edge object at 0x000001E32F0F0610>]]
Out[1]:
[[<build123d.topology.Edge at 0x1e316b544d0>],
 [<build123d.topology.Edge at 0x1e316c2b310>,
  <build123d.topology.Edge at 0x1e32ec0dc50>],
 [<build123d.topology.Edge at 0x1e30f5aaed0>,
  <build123d.topology.Edge at 0x1e32f0f0610>],
 [<build123d.topology.Edge at 0x1e32f08f550>,
  <build123d.topology.Edge at 0x1e30f610c10>],
 [<build123d.topology.Edge at 0x1e3175e4e90>,
  <build123d.topology.Edge at 0x1e32f0dc050>]]

N.B. in a standard python REPL the return value of the last statement will be equivalent to the second print statement.

Copy link

codecov bot commented Feb 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (72827ff) 96.24% compared to head (1c61a13) 96.25%.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev     #560   +/-   ##
=======================================
  Coverage   96.24%   96.25%           
=======================================
  Files          24       24           
  Lines        7746     7760   +14     
=======================================
+ Hits         7455     7469   +14     
  Misses        291      291           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@gumyr gumyr merged commit 1717698 into gumyr:dev Feb 22, 2024
13 checks passed
@jdegenstein jdegenstein deleted the groupby_str_repr branch January 2, 2025 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants