Skip to content

Unicode and console unit representations sometimes include an extraneous space #14409

Closed

Description

@mhvk

Description

As noted in #14407, for units typset in unicode or console format, a space is included in front, unlike for regular units, yet it is sometimes omitted if a unit scale factor is present.

Expected behavior

unit.to_string(format) should never start with a space, independent of format.

How to Reproduce

From https://github.com/astropy/astropy/pull/14407/files#r1108987447 and https://github.com/astropy/astropy/pull/14407/files#r1109066798:

import astropy.units as u
print(f'{(u.m**-1):unicode}')
 1
 ─
 m
f"{(u.eV*u.s**2).decompose()}"             # space between scale and unit
'1.60218e-19 kg m2'
f"{(u.eV*u.s**2).decompose():unicode}"     # no space between scale and unit
'1.6021766×10⁻¹⁹m² kg'
f"{(1*u.eV*u.s**2).decompose()}"           # space between value and unit
'1.602176634e-19 kg m2'
f"{(1 * u.eV*u.s**2).decompose():unicode}" # space between value and unit
'1.602176634e-19 m² kg'

Versions

Any astropy really.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions