Skip to content

Inheritance and instance-ship of astropy units unexpected #6517

Closed

Description

@maxnoe

The base siunits are of class IrreducibleUnit, which does not inherit from Unit, which leads to some highly unexpected results.

>>> isinstance(u.m, u.Unit)
False
>>> isinstance(u.cm, u.Unit)
True
>>> isinstance(u.V, u.Unit)
True
>>> isinstance(u.A, u.Unit)
False

Activity

  1. pllim commented on Sep 6, 2017

    @pllim
    Member

    A workaround for now is either to use

    isinstance(my_unit, u.NamedUnit)

    or

    isinstance(my_unit, u.UnitBase)
  2. pllim commented on Sep 6, 2017

    @pllim
    Member

    Not sure if this is a bug or by design but the inheritance diagram here might also help:
    http://astropy.readthedocs.io/en/latest/units/index.html#id2

  3. mhvk commented on Apr 13, 2018

    @mhvk
    Contributor

    Came across this while looking at older issues. The inheritance is confusing. As @pllim notes, the default would be to do ininstance(unit, u.UnitBase) but this does not capture logarithmic units. I think we do need the abstract type discussed in #3650 -- indeed, I'll close this in favour of that issue (I copied the example on the top 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