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.
(
draw: st.DrawFn,
*,
array_strategy_fn: ArrayStrategyFn | None = None,
dims: st.SearchStrategy[Sequence[Hashable] | Mapping[Hashable, int]] | None = None,
dtype: st.SearchStrategy[np.dtype] | None = None,
attrs: st.SearchStrategy[Mapping] = ATTRS,
)
| 253 | |
| 254 | @st.composite |
| 255 | def variables( |
| 256 | draw: st.DrawFn, |
| 257 | *, |
| 258 | array_strategy_fn: ArrayStrategyFn | None = None, |
| 259 | dims: st.SearchStrategy[Sequence[Hashable] | Mapping[Hashable, int]] | None = None, |
| 260 | dtype: st.SearchStrategy[np.dtype] | None = None, |
| 261 | attrs: st.SearchStrategy[Mapping] = ATTRS, |
| 262 | ) -> xr.Variable: |
| 263 | """ |
| 264 | Generates arbitrary xarray.Variable objects. |
| 265 | |
| 266 | Follows the basic signature of the xarray.Variable constructor, but allows passing alternative strategies to |
| 267 | generate either numpy-like array data or dimensions. Also allows specifying the shape or dtype of the wrapped array |
| 268 | up front. |
| 269 | |
| 270 | Passing nothing will generate a completely arbitrary Variable (containing a numpy array). |
| 271 | |
| 272 | Requires the hypothesis package to be installed. |
| 273 | |
| 274 | Parameters |
| 275 | ---------- |
| 276 | array_strategy_fn: Callable which returns a strategy generating array-likes, optional |
| 277 | Callable must only accept shape and dtype kwargs, and must generate results consistent with its input. |
| 278 | If not passed the default is to generate a small numpy array with one of the supported_dtypes. |
| 279 | dims: Strategy for generating the dimensions, optional |
| 280 | Can either be a strategy for generating a sequence of string dimension names, |
| 281 | or a strategy for generating a mapping of string dimension names to integer lengths along each dimension. |
| 282 | If provided as a mapping the array shape will be passed to array_strategy_fn. |
| 283 | Default is to generate arbitrary dimension names for each axis in data. |
| 284 | dtype: Strategy which generates np.dtype objects, optional |
| 285 | Will be passed in to array_strategy_fn. |
| 286 | Default is to generate any scalar dtype using supported_dtypes. |
| 287 | Be aware that this default set of dtypes includes some not strictly allowed by the array API standard. |
| 288 | attrs: Strategy which generates dicts, optional |
| 289 | Default is to generate a nested attributes dictionary containing arbitrary strings, booleans, integers, Nones, |
| 290 | and numpy arrays. |
| 291 | |
| 292 | Returns |
| 293 | ------- |
| 294 | variable_strategy |
| 295 | Strategy for generating xarray.Variable objects. |
| 296 | |
| 297 | Raises |
| 298 | ------ |
| 299 | ValueError |
| 300 | If a custom array_strategy_fn returns a strategy which generates an example array inconsistent with the shape |
| 301 | & dtype input passed to it. |
| 302 | |
| 303 | Examples |
| 304 | -------- |
| 305 | Generate completely arbitrary Variable objects backed by a numpy array: |
| 306 | |
| 307 | >>> variables().example() # doctest: +SKIP |
| 308 | <xarray.Variable (żō: 3)> |
| 309 | array([43506, -16, -151], dtype=int32) |
| 310 | >>> variables().example() # doctest: +SKIP |
| 311 | <xarray.Variable (eD: 4, ğŻżÂĕ: 2, T: 2)> |
| 312 | array([[[-10000000., -10000000.], |
searching dependent graphs…