Skip to content

Space between value and unit #7455

Closed

Description

@astrofrog

Currently, Angle.to_string doesn't include a space between the value and unit:

In [30]: from astropy.coordinates import Angle

In [31]: a = Angle(3, 'deg')

In [32]: a.to_string(unit='mas')
Out[32]: '1.08e+07mas'

I think there are cases where it would make sense to allow a space to be included, so this is a feature request to add a boolean keyword argument to optionally add a space.

Note that Quantity does include a space by default so maybe actually we should just change the default and not add an option?

In [17]: str(3 * u.mas)
Out[17]: '3.0 mas'

Activity

  1. Cadair commented on May 11, 2018

    @Cadair
    Member

    isn't it good form to always have a space between the value and the unit?

  2. pllim commented on May 11, 2018

    @pllim
    Member

    👍 for consistency between Quantity and Angle (by having space as default).

    However, if you worry about backward compatibility, maybe instead add an option for "old style" (without space), but would that be useful for anyone?

  3. astrofrog commented on May 11, 2018

    @astrofrog
    MemberAuthor

    Well the one place where we don't want a space is when using a symbol, e.g. 3.4"

  4. pllim commented on May 11, 2018

    @pllim
    Member

    Re: symbol -- Nothing some regex wouldn't fix... 😉 (show self to door)

  5. larrybradley commented on Jun 20, 2018

    @larrybradley
    Member

    @astrofrog I think we should use a space by default (probably the most common use case), and then add a boolean keyword argument to optionally not include a space (e.g. 3.4").

  6. astrofrog commented on Jun 20, 2018

    @astrofrog
    MemberAuthor

    I agree!

  7. daspartho commented on Aug 15, 2022

    @daspartho

    can i work on this

  8. Telomelonia commented on Dec 24, 2022

    @Telomelonia
    Member

    👍 for consistency between Quantity and Angle (by having space as default).

    However, if you worry about backward compatibility, maybe instead add an option for "old style" (without space), but would that be useful for anyone?

    @pllim I have implemented your idea in the PR attached; please see to it.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions