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

Function test_findall_single_multi_case

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

Source from the content-addressed store, hash-verified

1271
1272
1273def test_findall_single_multi_case(dtype) -> None:
1274 pat_str = r"(\w+)_Xy_\d*"
1275 pat_re = re.compile(dtype(pat_str))
1276
1277 value = xr.DataArray(
1278 [
1279 ["a_Xy_0", "ab_xY_10-bab_Xy_110-baab_Xy_1100", "abc_Xy_01-cbc_Xy_2210"],
1280 [
1281 "abcd_Xy_-dcd_Xy_33210-dccd_Xy_332210",
1282 "",
1283 "abcdef_Xy_101-fef_Xy_5543210",
1284 ],
1285 ],
1286 dims=["X", "Y"],
1287 ).astype(dtype)
1288
1289 expected_list: list[list[list]] = [
1290 [["a"], ["bab", "baab"], ["abc", "cbc"]],
1291 [
1292 ["abcd", "dcd", "dccd"],
1293 [],
1294 ["abcdef", "fef"],
1295 ],
1296 ]
1297 expected_dtype = [[[dtype(x) for x in y] for y in z] for z in expected_list]
1298 expected_np = np.array(expected_dtype, dtype=np.object_)
1299 expected = xr.DataArray(expected_np, dims=["X", "Y"])
1300
1301 res_str = value.str.findall(pat=pat_str)
1302 res_re = value.str.findall(pat=pat_re)
1303 res_str_case = value.str.findall(pat=pat_str, case=True)
1304
1305 assert res_str.dtype == expected.dtype
1306 assert res_re.dtype == expected.dtype
1307 assert res_str_case.dtype == expected.dtype
1308
1309 assert_equal(res_str, expected)
1310 assert_equal(res_re, expected)
1311 assert_equal(res_str_case, expected)
1312
1313
1314def test_findall_single_multi_nocase(dtype) -> None:

Callers

nothing calls this directly

Calls 4

assert_equalFunction · 0.90
findallMethod · 0.80
dtypeFunction · 0.70
astypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…