Skip to content

unit dropped from formatted string of 0d quantity array  #156

Description

@twmr

In numpy/numpy#9883 (part of numpy 1.14) the behavior of the formatting of 0d numpy arrays was changed. This unfortunately broke support for formatting (magnitude + unit) quantities using str.format:

In [2]: "{}".format(3*pq.m)
Out[2]: '3.0'

whereas with an older version of numpy (< 1.14) the unit is included in the formatted string:

In [2]: "{}".format(3*pq.m)
Out[2]: '3.0 m'

My current workaround is to use the !s conversion flag:

In [2]: "{!s}".format(3*pq.m)
Out[2]: '3.0 m'

Apparently unyt doesn't have this problem:
yt-project/unyt#89

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions