xarray.as_variable(obj, name=None, auto_convert=True)[source]#

Convert an object into a Variable.

  • obj (object) – Object to convert into a Variable.

    • If the object is already a Variable, return a shallow copy.

    • Otherwise, if the object has ‘dims’ and ‘data’ attributes, convert it into a new Variable.

    • If all else fails, attempt to convert the object into a Variable by unpacking it into the arguments for creating a new Variable.

  • name (str, optional) – If provided:

    • obj can be a 1D array, which is assumed to label coordinate values along a dimension of this given name.

    • Variables with name matching one of their dimensions are converted into IndexVariable objects.

  • auto_convert (bool, optional) – For internal use only! If True, convert a “dimension” variable into an IndexVariable object (deprecated).


var (Variable) – The newly created variable.