Skip to content

Commit

Permalink
Merge 44505db into f38517f
Browse files Browse the repository at this point in the history
  • Loading branch information
pllim committed Mar 24, 2017
2 parents f38517f + 44505db commit 0782959
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Expand Up @@ -124,6 +124,9 @@ API Changes

- ``astropy.units``

- Moved ``units.cgs.emu`` to ``units.deprecated.emu`` due to ambiguous
definition of "emu". [#4918, #5906]

- ``astropy.utils``

- ``astropy.visualization``
Expand Down
2 changes: 1 addition & 1 deletion astropy/units/cgs.py
Expand Up @@ -97,7 +97,7 @@
def_unit(['statA', 'statampere'], Fr * s ** -1, namespace=_ns,
doc='statampere: CGS (ESU) unit of current')

def_unit(['Bi', 'Biot', 'abA', 'abampere', 'emu'],
def_unit(['Bi', 'Biot', 'abA', 'abampere'],
g ** Fraction(1, 2) * cm ** Fraction(1, 2) * s ** -1, namespace=_ns,
doc='Biot: CGS (EMU) unit of current')

Expand Down
62 changes: 62 additions & 0 deletions astropy/units/deprecated.py
@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*-
# Licensed under a 3-clause BSD style license - see LICENSE.rst
"""This package defines deprecated units.
These units are not available in the top-level `astropy.units`
namespace. To use these units, you must import the `astropy.units.deprecated`
module::
>>> from astropy.units import deprecated
>>> q = 10. * deprecated.emu # doctest: +SKIP
To include them in `~astropy.units.UnitBase.compose` and the results of
`~astropy.units.UnitBase.find_equivalent_units`, do::
>>> from astropy.units import deprecated
>>> deprecated.enable() # doctest: +SKIP
"""
from __future__ import (absolute_import, division, print_function,
unicode_literals)

_ns = globals()


def _initialize_module():
# Local imports to avoid polluting top-level namespace
from . import cgs
from .core import def_unit

def_unit(['emu'], cgs.Bi, namespace=_ns,
doc='Biot: CGS (EMU) unit of current')


_initialize_module()


###########################################################################
# DOCSTRING

# This generates a docstring for this module that describes all of the
# standard units defined here.
from .utils import generate_unit_summary as _generate_unit_summary # noqa
if __doc__ is not None:
__doc__ += _generate_unit_summary(globals())


def enable():
"""
Enable deprecated units so they appear in results of
`~astropy.units.UnitBase.find_equivalent_units` and
`~astropy.units.UnitBase.compose`. This will disable
all of the "default" `astropy.units` units, since there
are some namespace clashes between the two.
This may be used with the ``with`` statement to enable deprecated
units only temporarily.
"""
# Local import to avoid cyclical import
from .core import set_enabled_units
# Local import to avoid polluting namespace
import inspect
return set_enabled_units(inspect.getmodule(enable))
24 changes: 24 additions & 0 deletions astropy/units/tests/test_deprecated.py
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# Licensed under a 3-clause BSD style license - see LICENSE.rst

# TEST_UNICODE_LITERALS

"""Regression tests for deprecated units."""
from __future__ import (absolute_import, unicode_literals, division,
print_function)

from .. import deprecated
from ... import units as u
from ...tests.helper import pytest # TODO: Stop using bundled pytest


def test_emu():
with pytest.raises(AttributeError):
u.emu

assert u.Bi.to(deprecated.emu, 1) == 1

with deprecated.enable():
assert u.Bi.compose()[0] == deprecated.emu

assert u.Bi.compose()[0] == u.Bi
4 changes: 3 additions & 1 deletion docs/units/index.rst
Expand Up @@ -106,7 +106,7 @@ parentheses to create a corresponding logarithmic quantity::
>>> from astropy import constants as c
>>> u.Dex((c.G * u.M_sun / u.R_sun**2).cgs) # doctest: +FLOAT_CMP
<Dex 4.43842814841305 dex(cm / s2)>

`astropy.units` also handles :ref:`equivalencies <unit_equivalencies>`, such as
that between wavelength and frequency. To use that feature, equivalence objects
are passed to the :meth:`~astropy.units.quantity.Quantity.to` conversion
Expand Down Expand Up @@ -207,6 +207,8 @@ Reference/API

.. automodapi:: astropy.units.function

.. automodapi:: astropy.units.deprecated

Acknowledgments
===============

Expand Down

0 comments on commit 0782959

Please sign in to comment.