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

[REGR} formatter does not handle negative powers in numerator correctly #1983

Open
andrewgsavage opened this issue May 12, 2024 · 1 comment

Comments

@andrewgsavage
Copy link
Collaborator

The doctests were failing. I've changed them to get them working again:

# Old docs
    >>> print(formatter(result[0].items()))
    T * V / L
# Current docs 
    >>> numerator = [item for item in result[0].items() if item[1]>0]
    >>> denominator = [item for item in result[0].items() if item[1]<0]
    >>> print(formatter(numerator, denominator))
    V * T / L

This feels uncessarily clunky

@andrewgsavage
Copy link
Collaborator Author

I've added the first line (commented here) to avoid this error message:
docs\user\formatting.rst

     10 # >>> ureg.formatter._registry = ureg
     11 q = ureg.Quantity(2,"m")
---> 12 str(q)
     13 '2.3e-06 ups!'

File F:\A\repos\pint\pint\facets\plain\quantity.py:270, in PlainQuantity.__str__(self)
    269 def __str__(self) -> str:
--> 270     return self._REGISTRY.formatter.format_quantity(self)

File F:\A\repos\pint\pint\delegates\formatter\plain.py:129, in DefaultFormatter.format_quantity(self, quantity, qspec, sort_func, **babel_kwds)
    122 """Format a quantity (magnitude and unit) into string
    123 given a string formatting specification and locale related arguments.
    124 """
    126 registry = self._registry
    128 mspec, uspec = split_format(
--> 129     qspec, registry.formatter.default_format, registry.separate_format_defaults
    130 )
    132 joint_fstring = "{} {}"
    133 return join_mu(
    134     joint_fstring,
    135     self.format_magnitude(quantity.magnitude, mspec, **babel_kwds),
    136     self.format_unit(quantity.unit_items(), uspec, sort_func, **babel_kwds),
    137 )

AttributeError: 'NoneType' object has no attribute 'formatter'

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

No branches or pull requests

1 participant