MCPcopy Index your code
hub / github.com/pydata/xarray / test_get_dummies

Function test_get_dummies

xarray/tests/test_accessor_str.py:2972–3013  ·  view source on GitHub ↗
(dtype)

Source from the content-addressed store, hash-verified

2970
2971
2972def test_get_dummies(dtype) -> None:
2973 values_line = xr.DataArray(
2974 [["a|ab~abc|abc", "ab", "a||abc|abcd"], ["abcd|ab|a", "abc|ab~abc", "|a"]],
2975 dims=["X", "Y"],
2976 ).astype(dtype)
2977 values_comma = xr.DataArray(
2978 [["a~ab|abc~~abc", "ab", "a~abc~abcd"], ["abcd~ab~a", "abc~ab|abc", "~a"]],
2979 dims=["X", "Y"],
2980 ).astype(dtype)
2981
2982 vals_line = np.array(["a", "ab", "abc", "abcd", "ab~abc"]).astype(dtype)
2983 vals_comma = np.array(["a", "ab", "abc", "abcd", "ab|abc"]).astype(dtype)
2984 expected_list = [
2985 [
2986 [True, False, True, False, True],
2987 [False, True, False, False, False],
2988 [True, False, True, True, False],
2989 ],
2990 [
2991 [True, True, False, True, False],
2992 [False, False, True, False, True],
2993 [True, False, False, False, False],
2994 ],
2995 ]
2996 expected_np = np.array(expected_list)
2997 expected = xr.DataArray(expected_np, dims=["X", "Y", "ZZ"])
2998 targ_line = expected.copy()
2999 targ_comma = expected.copy()
3000 targ_line.coords["ZZ"] = vals_line
3001 targ_comma.coords["ZZ"] = vals_comma
3002
3003 res_default = values_line.str.get_dummies(dim="ZZ")
3004 res_line = values_line.str.get_dummies(dim="ZZ", sep="|")
3005 res_comma = values_comma.str.get_dummies(dim="ZZ", sep="~")
3006
3007 assert res_default.dtype == targ_line.dtype
3008 assert res_line.dtype == targ_line.dtype
3009 assert res_comma.dtype == targ_comma.dtype
3010
3011 assert_equal(res_default, targ_line)
3012 assert_equal(res_line, targ_line)
3013 assert_equal(res_comma, targ_comma)
3014
3015
3016def test_get_dummies_broadcast(dtype) -> None:

Callers

nothing calls this directly

Calls 4

copyMethod · 0.95
assert_equalFunction · 0.90
get_dummiesMethod · 0.80
astypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…