MCPcopy
hub / github.com/pydata/xarray / test_splitters_broadcast

Function test_splitters_broadcast

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

Source from the content-addressed store, hash-verified

2896
2897
2898def test_splitters_broadcast(dtype) -> None:
2899 values = xr.DataArray(
2900 ["ab cd,de fg", "spam, ,eggs swallow", "red_blue"],
2901 dims=["X"],
2902 ).astype(dtype)
2903
2904 sep = xr.DataArray(
2905 [" ", ","],
2906 dims=["Y"],
2907 ).astype(dtype)
2908
2909 expected_left = xr.DataArray(
2910 [
2911 [["ab", "cd,de fg"], ["ab cd", "de fg"]],
2912 [["spam,", ",eggs swallow"], ["spam", " ,eggs swallow"]],
2913 [["red_blue", ""], ["red_blue", ""]],
2914 ],
2915 dims=["X", "Y", "ZZ"],
2916 ).astype(dtype)
2917 expected_right = xr.DataArray(
2918 [
2919 [["ab cd,de", "fg"], ["ab cd", "de fg"]],
2920 [["spam, ,eggs", "swallow"], ["spam, ", "eggs swallow"]],
2921 [["", "red_blue"], ["", "red_blue"]],
2922 ],
2923 dims=["X", "Y", "ZZ"],
2924 ).astype(dtype)
2925
2926 res_left = values.str.split(dim="ZZ", sep=sep, maxsplit=1)
2927 res_right = values.str.rsplit(dim="ZZ", sep=sep, maxsplit=1)
2928
2929 # assert res_left.dtype == expected_left.dtype
2930 # assert res_right.dtype == expected_right.dtype
2931
2932 assert_equal(res_left, expected_left)
2933 assert_equal(res_right, expected_right)
2934
2935 expected_left = xr.DataArray(
2936 [
2937 [["ab", " ", "cd,de fg"], ["ab cd", ",", "de fg"]],
2938 [["spam,", " ", ",eggs swallow"], ["spam", ",", " ,eggs swallow"]],
2939 [["red_blue", "", ""], ["red_blue", "", ""]],
2940 ],
2941 dims=["X", "Y", "ZZ"],
2942 ).astype(dtype)
2943 expected_right = xr.DataArray(
2944 [
2945 [["ab", " ", "cd,de fg"], ["ab cd", ",", "de fg"]],
2946 [["spam,", " ", ",eggs swallow"], ["spam", ",", " ,eggs swallow"]],
2947 [["red_blue", "", ""], ["red_blue", "", ""]],
2948 ],
2949 dims=["X", "Y", "ZZ"],
2950 ).astype(dtype)
2951
2952 res_left = values.str.partition(dim="ZZ", sep=sep)
2953 res_right = values.str.partition(dim="ZZ", sep=sep)
2954
2955 # assert res_left.dtype == expected_left.dtype

Callers

nothing calls this directly

Calls 5

assert_equalFunction · 0.90
splitMethod · 0.80
rsplitMethod · 0.80
partitionMethod · 0.80
astypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…