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

ENH: use Fraction for spin values #288

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft

Conversation

grayson-helmholz
Copy link
Contributor

If the Spin class would have the types of its fields magnitude & projection to be of
the Fraction-type, it would simplyfy the validation of their values (multiples of 1/2,
projection <= magnitude, etc.)

@redeboer redeboer self-requested a review October 4, 2024 15:18
@grayson-helmholz grayson-helmholz linked an issue Oct 4, 2024 that may be closed by this pull request
@redeboer redeboer added the ⚙️ Enhancement Improvements and optimizations of existing features label Oct 4, 2024
@redeboer redeboer marked this pull request as ready for review October 8, 2024 14:25
else:
p.pretty(value) # type: ignore[attr-defined]
p.text(",")
p.breakable()
p.text(")")


def _float_as_signed_fraction_str(value: float, render_plus: bool = False) -> str:
Copy link
Member

Choose a reason for hiding this comment

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

I was curious why there is a cast to Fraction. Maybe a doctest would be useful:

Suggested change
def _float_as_signed_fraction_str(value: float, render_plus: bool = False) -> str:
def _float_as_signed_fraction_str(value: float, render_plus: bool = False) -> str:
"""Convert a float to a fraction string with optional sign.
>>> _float_as_signed_fraction_str(1.5)
'3/2'
>>> _float_as_signed_fraction_str(-1.5)
'-3/2'
"""

@redeboer redeboer marked this pull request as draft October 8, 2024 14:28
@redeboer redeboer changed the title Change the Spin class to have magnitude & projection as Fractions ENH: use Fraction for spin values Oct 8, 2024
@redeboer
Copy link
Member

redeboer commented Oct 8, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚙️ Enhancement Improvements and optimizations of existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Write spin magnitude and projection as Fraction
2 participants