Skip to content

format_unit() with ^ flag should use negative powers for standalone units #2313

@juhuebner

Description

@juhuebner

When formatting standalone units with ^ in the spec, format_unit() currently prints ratio form (1/s) instead of negative-power form (s⁻¹), while format_quantity() already behaves correctly.

Example:

  • ureg.Unit("second")**-1 with "{:~^P}" should print s⁻¹
  • currently returns 1/s

This appears to be because FullFormatter.format_unit() does not pass as_ratio=False when ^ is present, unlike format_quantity().

A fix would be to update pint/delegates/formatter/full.py so format_unit() mirrors the ^ handling in format_quantity().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions