Skip to content

cannot import name 'imperials' from 'astropy.units' #11975

Closed

Description

@erwanp

Description

Our spectroscopy package radis depends on Astropy.units. Latest build fetched astropy==4.3
and failed with the following error :

AttributeError: module 'astropy.units' has no attribute 'imperial'

Expected behavior

Original code worked :

import astropy.units as u
u.K in (u.K, u.imperial.deg_F)
>>> cannot import name 'imperials' from 'astropy.units'

Now I have to update the code to

import astropy.units as u
from astropy.units.imperial import deg_F 
u.K in (u.K, deg_F)
>>> True

If this is the expected behavior (and cleaner way to import), this Issue can be closed right away. Hopefully the title will help people that would encounter the same proper to find an easy fix.

Activity

  1. github-actions commented on Jul 27, 2021

    @github-actions
    Contributor

    Welcome to Astropy 👋 and thank you for your first issue!

    A project member will respond to you as soon as possible; in the meantime, please double-check the guidelines for submitting issues and make sure you've provided the requested details.

    If you feel that this issue has not been responded to in a timely manner, please leave a comment mentioning our software support engineer @embray, or send a message directly to the development mailing list. If the issue is urgent or sensitive in nature (e.g., a security vulnerability) please send an e-mail directly to the private e-mail [email protected].

  2. added a commit that references this issue on Jul 27, 2021
  3. astrofrog commented on Jul 27, 2021

    @astrofrog
    Member

    I'm running into the same issue with PyWWT using u.imperial:

    In [1]: from astropy import units as u
    
    In [2]: u.imperial
    ---------------------------------------------------------------------------
    AttributeError                            Traceback (most recent call last)
    <ipython-input-2-f25c0008b10d> in <module>
    ----> 1 u.imperial
    
    AttributeError: module 'astropy.units' has no attribute 'imperial'
    
  4. astrofrog commented on Jul 27, 2021

    @astrofrog
    Member

    I think this is going to require a quick v4.3.1 follow-up (at the very least there should be a deprecation warning if this was intentional)

  5. dhomeier commented on Jul 27, 2021

    @dhomeier
    Contributor

    from astropy.units.imperial import deg_F
    u.K in (u.K, deg_F)

    Until then a less intrusive workaround will probably be

    import astropy.units.imperial
    u.K in (u.K, u.imperial.deg_F)
  6. pllim commented on Jul 27, 2021

    @pllim
    Member

    Oh, dear! See #11977

  7. pllim commented on Jul 27, 2021

    @pllim
    Member

    FYI to packages affected by this: Going forward, we highly recommend adding a CI job to test against astropy dev, or at the very least test the release candidate when it is announced.

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