Skip to content

Should use of SortBy enums or properties work gracefully if they don't exist? #949

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

Open
jdegenstein opened this issue Mar 25, 2025 · 2 comments
Labels
question Further information is requested

Comments

@jdegenstein
Copy link
Collaborator

a = Cylinder(1,1)
a.edges().filter_by(GeomType.CIRCLE).sort_by(Edge.radius) # works
a.edges().filter_by(GeomType.CIRCLE).sort_by(SortBy.RADIUS) # works
a.edges().sort_by(Edge.radius) # fails "ValueError: Shape could not be reduced to a circle"
a.edges().sort_by(SortBy.RADIUS) # fails "ValueError: Shape could not be reduced to a circle"

Should the latter two cases return the same as the former two cases? (i.e. an implicit filter)

@jwagenet
Copy link
Contributor

To expand my initial thoughts:

part.edges().filter_by(GeomType.CIRCLE).group_by(Edge.radius) requires the GeomType filter to avoid a ValueError kickback from OCP for an incompatible GeomType in a mixed-type list of edges. ShapeList methods like group_by(Edge.radius) or filter_by(lambda e: e.radius == 8) could handle the errors so the GeomType filter isn't necessary or the properties themselves dont throw the error.

If handling within the properties, returning None seems safest.

If handling in operators, filter can could treat error cases as the False case.
For sort/group its a little more complicated as returning a 'zero' value eg Line().radius == 0 really right in this case. Returning None wouldn't play well with sort, unless error/None values are implicitly filtered. None can work as a key in GroupBy, but it would need to be excluded from list slicing.

@gumyr gumyr added the question Further information is requested label Mar 27, 2025
@gumyr gumyr added this to the Not Gating Release 1.0.0 milestone Mar 27, 2025
@gumyr
Copy link
Owner

gumyr commented Mar 27, 2025

I'm not sure that making sort_by into an implicit filter_by is very intuitive (and it probably breaks some of the Python guidelines). I don't think any sort should have the property of changing the length of the list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants