def test_xr_coords_dicts(dims, sizes, unique_coords, data): elements = None min_side, max_side = sizes # special dims just filled with dim name on coords as test case special_dims = data.draw(hxr.subset_lists(dims)) coords_st = { dd: lists(just(dd), min_side, max_side) for dd in special_dims } S = hxr.xr_coords_dicts(dims, elements, min_side, max_side, unique_coords, coords_st) D = data.draw(S) assert list(D.keys()) == dims assert all(min_side <= len(cc) for cc in D.values()) assert (max_side is None) or all(max_side >= len(cc) for cc in D.values()) assert all((dd in special_dims) or all(isinstance(ss, int) for ss in L) for dd, L in D.items()) assert all(all(ss == dd for ss in D[dd]) for dd in special_dims) if unique_coords: for dd, cc in D.items(): assert (dd in special_dims) or (len(set(cc)) == len(cc))
def test_get_all_dims(dims, data): vars_to_dims = data.draw(hxr.xr_coords_dicts(dims)) all_dims = hxr._get_all_dims(vars_to_dims) assert all_dims == sorted(set(all_dims)) all_dims2 = [] for dd in vars_to_dims.values(): all_dims2.extend(dd) assert all_dims == sorted(set(all_dims2))
def test_fixed_coords_dataarrays(dims, dtype, data): elements = None coords = data.draw(hxr.xr_coords_dicts(dims)) S = hxr.fixed_coords_dataarrays(dims, coords, dtype, elements) da = data.draw(S) assert da.dims == tuple(dims) assert da.dtype == np.dtype(dtype) for dd in dims: assert da.coords[dd].values.tolist() == coords[dd]
def test_fixed_coords_datasets_no_dtype(vars_to_dims, data): elements = None all_dims = sorted(set(sum((list(dd) for dd in vars_to_dims.values()), []))) coords = data.draw(hxr.xr_coords_dicts(all_dims)) S = hxr.fixed_coords_datasets(vars_to_dims, coords, dtype=None, elements=elements) ds = data.draw(S) assert list(ds) == list(vars_to_dims.keys()) assert all(ds[vv].dims == tuple(vars_to_dims[vv]) for vv in vars_to_dims) assert all(ds[vv].dtype == np.dtype(hxr.DEFAULT_DTYPE) for vv in vars_to_dims) for dd in all_dims: L = ds.coords[dd].values.tolist() assert L == coords[dd]