# xarray.testing.strategies.variables

### xarray.testing.strategies.variables(, array_strategy_fn=None, dims=None, dtype=None, attrs=recursive(dictionaries(keys=text(alphabet=characters(max_codepoint=383, categories=['L', 'N']), max_size=5), values=one_of(none(), booleans(), text(alphabet=characters(max_codepoint=383, categories=['L', 'N']), max_size=5), arrays(dtype=one_of(scalar_dtypes(), byte_string_dtypes(), unicode_string_dtypes()), shape=array_shapes(max_dims=2, max_side=2)))), lambda children: ..., min_leaves=None, max_leaves=3))

Generates arbitrary xarray.Variable objects.

Follows the basic signature of the xarray.Variable constructor, but allows passing alternative strategies to
generate either numpy-like array data or dimensions. Also allows specifying the shape or dtype of the wrapped array
up front.

Passing nothing will generate a completely arbitrary Variable (containing a numpy array).

Requires the hypothesis package to be installed.

* **Parameters:**
  * **array_strategy_fn** (`Callable which returns a strategy generating array-likes`, *optional*) – Callable must only accept shape and dtype kwargs, and must generate results consistent with its input.
    If not passed the default is to generate a small numpy array with one of the supported_dtypes.
  * **dims** (`Strategy for generating the dimensions`, *optional*) – Can either be a strategy for generating a sequence of string dimension names,
    or a strategy for generating a mapping of string dimension names to integer lengths along each dimension.
    If provided as a mapping the array shape will be passed to array_strategy_fn.
    Default is to generate arbitrary dimension names for each axis in data.
  * **dtype** (`Strategy which generates np.dtype objects`, *optional*) – Will be passed in to array_strategy_fn.
    Default is to generate any scalar dtype using supported_dtypes.
    Be aware that this default set of dtypes includes some not strictly allowed by the array API standard.
  * **attrs** (`Strategy which generates dicts`, *optional*) – Default is to generate a nested attributes dictionary containing arbitrary strings, booleans, integers, Nones,
    and numpy arrays.
* **Returns:**
  `variable_strategy` – Strategy for generating xarray.Variable objects.
* **Raises:**
  [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If a custom array_strategy_fn returns a strategy which generates an example array inconsistent with the shape
      & dtype input passed to it.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('32c68098-e172-4455-be9b-792e0aed2a6b','49866496-76d1-42fd-b65c-2d299f3ddd9e','556f27b8-b244-4eb6-b469-fbf6895ef584','../lite/tree/../notebooks/index.html?path=d02da6ea_51db_417a_a6d8_d4fa312c4d41.ipynb','None')">Try it in your browser!</button></div>

Generate completely arbitrary Variable objects backed by a numpy array:

```pycon
>>> variables().example()
<xarray.Variable (żō: 3)>
array([43506,   -16,  -151], dtype=int32)
>>> variables().example()
<xarray.Variable (eD: 4, ğŻżÂĕ: 2, T: 2)>
array([[[-10000000., -10000000.],
        [-10000000., -10000000.]],
       [[-10000000., -10000000.],
        [        0., -10000000.]],
       [[        0., -10000000.],
        [-10000000.,        inf]],
       [[       -0., -10000000.],
        [-10000000.,        -0.]]], dtype=float32)
Attributes:
    śřĴ:      {'ĉ': {'iĥf': array([-30117,  -1740], dtype=int16)}}
```

Generate only Variable objects with certain dimension names:

```pycon
>>> variables(dims=st.just(["a", "b"])).example()
<xarray.Variable (a: 5, b: 3)>
array([[       248, 4294967295, 4294967295],
       [2412855555, 3514117556, 4294967295],
       [       111, 4294967295, 4294967295],
       [4294967295, 1084434988,      51688],
       [     47714,        252,      11207]], dtype=uint32)
```

Generate only Variable objects with certain dimension names and lengths:

```pycon
>>> variables(dims=st.just({"a": 2, "b": 1})).example()
<xarray.Variable (a: 2, b: 1)>
array([[-1.00000000e+007+3.40282347e+038j],
       [-2.75034266e-225+2.22507386e-311j]])
```

<div id="556f27b8-b244-4eb6-b469-fbf6895ef584" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('32c68098-e172-4455-be9b-792e0aed2a6b','556f27b8-b244-4eb6-b469-fbf6895ef584')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('32c68098-e172-4455-be9b-792e0aed2a6b','556f27b8-b244-4eb6-b469-fbf6895ef584')">Open In Tab</button></div><div id="49866496-76d1-42fd-b65c-2d299f3ddd9e" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>

#### SEE ALSO
[Hypothesis testing](../user-guide/testing.html.md#testing-hypothesis)
