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

Function test_extractall_multi_single_case

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

Source from the content-addressed store, hash-verified

1024
1025
1026def test_extractall_multi_single_case(dtype) -> None:
1027 pat_str = r"(\w+)_Xy_(\d*)"
1028 pat_re: str | bytes = (
1029 pat_str if dtype == np.str_ else bytes(pat_str, encoding="UTF-8")
1030 )
1031 pat_compiled = re.compile(pat_re)
1032
1033 value = xr.DataArray(
1034 [["a_Xy_0", "ab_xY_10", "abc_Xy_01"], ["abcd_Xy_", "", "abcdef_Xy_101"]],
1035 dims=["X", "Y"],
1036 ).astype(dtype)
1037
1038 expected = xr.DataArray(
1039 [
1040 [[["a", "0"]], [["", ""]], [["abc", "01"]]],
1041 [[["abcd", ""]], [["", ""]], [["abcdef", "101"]]],
1042 ],
1043 dims=["X", "Y", "XX", "YY"],
1044 ).astype(dtype)
1045
1046 res_str = value.str.extractall(pat=pat_str, group_dim="XX", match_dim="YY")
1047 res_re = value.str.extractall(pat=pat_compiled, group_dim="XX", match_dim="YY")
1048 res_str_case = value.str.extractall(
1049 pat=pat_str, group_dim="XX", match_dim="YY", case=True
1050 )
1051
1052 assert res_str.dtype == expected.dtype
1053 assert res_re.dtype == expected.dtype
1054 assert res_str_case.dtype == expected.dtype
1055
1056 assert_equal(res_str, expected)
1057 assert_equal(res_re, expected)
1058 assert_equal(res_str_case, expected)
1059
1060
1061def test_extractall_multi_single_nocase(dtype) -> None:

Callers

nothing calls this directly

Calls 3

assert_equalFunction · 0.90
extractallMethod · 0.80
astypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…