<commit_before>.. doctest-skip-all

============
Known Issues
============

While most bugs and issues are managed using the `astropy issue
tracker <https://github.com/astropy/astropy/issues>`_, this document
lists issues that are too difficult to fix, may require some
intervention from the user to workaround, or are due to bugs in other
projects or packages.

.. _quantity_issues:

Quantities lose their units with some operations
------------------------------------------------

Quantities are subclassed from numpy's `~numpy.ndarray` and in some numpy operations
(and in scipy operations using numpy internally) the subclass is ignored, which
means that either a plain array is returned, or a `~astropy.units.quantity.Quantity` without units.
E.g.::

    >>> import astropy.units as u

    >>> import numpy as np

    >>> q = u.Quantity(np.arange(10.), u.m)

    >>> np.dot(q,q)
    285.0

    >>> np.hstack((q,q))
    <Quantity [ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 1., 2., 3., 4.,
                5., 6., 7., 8., 9.] (Unit not initialised)>

Work-arounds are available for some cases.  For the above::

    >>> q.dot(q)
    <Quantity 285.0 m2>

    >>> u.Quantity([q, q]).flatten()
    <Quantity [ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 1., 2., 3., 4.,
                5., 6., 7., 8., 9.] m>

See: https://github.com/astropy/astropy/issues/1274

Quantities float comparison with np.isclose fails
-------------------------------------------------

Comparing Quantities floats using the numpy function `~numpy.isclose` fails on
numpy 1.9 as the comparison between ``a`` and ``b`` is made using the formula

.. math::

    |a - b| \le (a_\textrm{tol} + r_\textrm{tol} \times |b|)

This will result in the following traceback when using this with Quantities::

    >>> from astropy import units as u, constants as const
    >>> import numpy as np
    >>> np.isclose(500* u.km/u.s, 300 * u.km / u.s)
    UnitsError: Can only apply 'add' function to dimensionless quantities when
    other argument is not a quantity (unless the latter is all zero/infinity/nan)

An easy solution is::

    >>> np.isclose(500* u.km/u.s, 300 * u.km / u.s, atol=1e-8 * u.mm / u.s)
    array([False], dtype=bool)<commit_msg>Added a list of numpy functions known to drop units<commit_after>.. doctest-skip-all

============
Known Issues
============

While most bugs and issues are managed using the `astropy issue
tracker <https://github.com/astropy/astropy/issues>`_, this document
lists issues that are too difficult to fix, may require some
intervention from the user to workaround, or are due to bugs in other
projects or packages.

.. _quantity_issues:

Quantities lose their units with some operations
------------------------------------------------

Quantities are subclassed from numpy's `~numpy.ndarray` and in some numpy operations
(and in scipy operations using numpy internally) the subclass is ignored, which
means that either a plain array is returned, or a `~astropy.units.quantity.Quantity` without units.
E.g.::

    >>> import astropy.units as u

    >>> import numpy as np

    >>> q = u.Quantity(np.arange(10.), u.m)

    >>> np.dot(q,q)
    285.0

    >>> np.hstack((q,q))
    <Quantity [ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 1., 2., 3., 4.,
                5., 6., 7., 8., 9.] (Unit not initialised)>

Work-arounds are available for some cases.  For the above::

    >>> q.dot(q)
    <Quantity 285.0 m2>

    >>> u.Quantity([q, q]).flatten()
    <Quantity [ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 1., 2., 3., 4.,
                5., 6., 7., 8., 9.] m>

An incomplete list of specific functions which are known to exhibit this behavior follows.

* `numpy.dot`
* `numpy.hstack`, `numpy.vstack`, ``numpy.c_``, ``numpy.r_``, `numpy.append`
* `numpy.where`
* `numpy.choose`
* `numpy.vectorize`
* pandas DataFrame(s)


See: https://github.com/astropy/astropy/issues/1274

Quantities float comparison with np.isclose fails
-------------------------------------------------

Comparing Quantities floats using the numpy function `~numpy.isclose` fails on
numpy 1.9 as the comparison between ``a`` and ``b`` is made using the formula

.. math::

    |a - b| \le (a_\textrm{tol} + r_\textrm{tol} \times |b|)

This will result in the following traceback when using this with Quantities::

    >>> from astropy import units as u, constants as const
    >>> import numpy as np
    >>> np.isclose(500* u.km/u.s, 300 * u.km / u.s)
    UnitsError: Can only apply 'add' function to dimensionless quantities when
    other argument is not a quantity (unless the latter is all zero/infinity/nan)

An easy solution is::

    >>> np.isclose(500* u.km/u.s, 300 * u.km / u.s, atol=1e-8 * u.mm / u.s)
    array([False], dtype=bool)
{'fraction_non_alphanumeric': 0.1866554054054054, 'fraction_numerical': 0.029983108108108107, 'mean_word_length': 2.5616541353383457, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 77, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5177656', 'n_tokens_mistral': 1645, 'n_tokens_neox': 1459, 'n_words': 577}