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

Function test_extract_broadcast

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

Source from the content-addressed store, hash-verified

841
842
843def test_extract_broadcast(dtype) -> None:
844 value = xr.DataArray(
845 ["a_Xy_0", "ab_xY_10", "abc_Xy_01"],
846 dims=["X"],
847 ).astype(dtype)
848
849 pat_str = xr.DataArray(
850 [r"(\w+)_Xy_(\d*)", r"(\w+)_xY_(\d*)"],
851 dims=["Y"],
852 ).astype(dtype)
853 pat_compiled = value.str._re_compile(pat=pat_str)
854
855 expected_list = [
856 [["a", "0"], ["", ""]],
857 [["", ""], ["ab", "10"]],
858 [["abc", "01"], ["", ""]],
859 ]
860 expected = xr.DataArray(expected_list, dims=["X", "Y", "Zz"]).astype(dtype)
861
862 res_str = value.str.extract(pat=pat_str, dim="Zz")
863 res_re = value.str.extract(pat=pat_compiled, dim="Zz")
864
865 assert res_str.dtype == expected.dtype
866 assert res_re.dtype == expected.dtype
867
868 assert_equal(res_str, expected)
869 assert_equal(res_re, expected)
870
871
872def test_extractall_single_single_case(dtype) -> None:

Callers

nothing calls this directly

Calls 4

assert_equalFunction · 0.90
_re_compileMethod · 0.80
extractMethod · 0.80
astypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…