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

Function test_findall_broadcast

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

Source from the content-addressed store, hash-verified

1506
1507
1508def test_findall_broadcast(dtype) -> None:
1509 value = xr.DataArray(
1510 ["a_Xy_0", "ab_xY_10", "abc_Xy_01"],
1511 dims=["X"],
1512 ).astype(dtype)
1513
1514 pat_str = xr.DataArray(
1515 [r"(\w+)_Xy_\d*", r"\w+_Xy_(\d*)"],
1516 dims=["Y"],
1517 ).astype(dtype)
1518 pat_re = value.str._re_compile(pat=pat_str)
1519
1520 expected_list: list[list[list]] = [[["a"], ["0"]], [[], []], [["abc"], ["01"]]]
1521 expected_dtype = [[[dtype(x) for x in y] for y in z] for z in expected_list]
1522 expected_np = np.array(expected_dtype, dtype=np.object_)
1523 expected = xr.DataArray(expected_np, dims=["X", "Y"])
1524
1525 res_str = value.str.findall(pat=pat_str)
1526 res_re = value.str.findall(pat=pat_re)
1527
1528 assert res_str.dtype == expected.dtype
1529 assert res_re.dtype == expected.dtype
1530
1531 assert_equal(res_str, expected)
1532 assert_equal(res_re, expected)
1533
1534
1535def test_repeat(dtype) -> None:

Callers

nothing calls this directly

Calls 5

assert_equalFunction · 0.90
_re_compileMethod · 0.80
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…