Skip to main content
`Ctrl`+`K`

# UnrecognizedUnit

class astropy.units.UnrecognizedUnit(st, doc=None, format=None, namespace=None)

  Bases: `IrreducibleUnit`

  A unit that did not parse correctly. This allows for round-tripping it as a string, but no unit operations actually work on it.

  Parameters:
    st `python:str`

      The name of the unit.

  Methods Summary

  `get_converter`(other[, equivalencies]) | Create a function that converts values from this unit to another.
  `is_equivalent`(other[, equivalencies]) | Check whether this unit is equivalent to `other`.
  `is_unity`() | Check whether the unit is unscaled and dimensionless.
  `to_string`([format]) | Output the unit in the given format as a string.

  Methods Documentation

  get_converter(other, equivalencies=None)

    Create a function that converts values from this unit to another.

    Parameters:
      other astropy:unit-like

        The unit to convert to.

      equivalencies `python:list` of `python:tuple`

        A list of equivalence pairs to try if the units are not directly convertible. See Equivalencies. This list is in addition to possible global defaults set by, e.g., `set_enabled_equivalencies`. Use `None` to turn off all equivalencies.

    Returns:
      func `python:callable()`

        A callable that takes an array-like argument and returns it converted from units of self to units of other.

    Raises:
      `UnitsError`

        If the units cannot be converted to each other.

    Notes

    This method is used internally in `Quantity` to convert to different units. Note that the function returned takes and returns values, not quantities.

  is_equivalent(other, equivalencies=None)

    Check whether this unit is equivalent to `other`.

    Parameters:
      other `Unit`, `python:str`, or `python:tuple`

        The unit to convert to. If a tuple of units is specified, this method returns true if the unit matches any of those in the tuple.

      equivalencies `python:list` of `python:tuple`

        A list of equivalence pairs to try if the units are not directly convertible. See Equivalencies. This list is in addition to possible global defaults set by, e.g., `set_enabled_equivalencies`. Use `None` to turn off all equivalencies.

    Returns:
      bool
  is_unity()

    Check whether the unit is unscaled and dimensionless.

  to_string(format=None)

    Output the unit in the given format as a string.

    Parameters:
      format `astropy.units.format.Base` subclass or `python:str` or `python:None`

        The name of a format or a formatter class. If not provided (or `None`), defaults to the generic format.

      **kwargs

        Further options forwarded to the formatter. Currently recognized is `fraction`, which can take the following values:

        - `False` : display unit bases with negative powers as they are;

        - ‘inline’ or `True` : use a single-line fraction;

        - ‘multiline’ : use a multiline fraction (available for the ‘latex’, ‘console’ and ‘unicode’ formats only; for others, an ‘inline’ fraction is used).

    Raises:
      `TypeError`

        If `format` is of the wrong type.

      `ValueError`

        If `format` or `fraction` are not recognized.

    Examples

        >>> import astropy.units as u
        >>> kms = u.Unit('km / s')
        >>> kms.to_string()  # Generic uses fraction='inline' by default
        'km / s'
        >>> kms.to_string('latex')  # Latex uses fraction='multiline' by default
        '$\\mathrm{\\frac{km}{s}}$'
        >>> print(kms.to_string('unicode', fraction=False))
        km s⁻¹
        >>> print(kms.to_string('unicode', fraction='inline'))
        km / s
        >>> print(kms.to_string('unicode', fraction='multiline'))
        km
        ──
        s