Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate emu unit #5906

Merged
merged 2 commits into from
Mar 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
61 changes: 61 additions & 0 deletions astropy/units/deprecated.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# -*- 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 may be used with the ``with`` statement to enable deprecated
units only temporarily.
"""
# Local import to avoid cyclical import
from .core import add_enabled_units
# Local import to avoid polluting namespace
import inspect
return add_enabled_units(inspect.getmodule(enable))
24 changes: 24 additions & 0 deletions astropy/units/tests/test_deprecated.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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