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

Function test_extract_multi_nocase

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

Source from the content-addressed store, hash-verified

804
805
806def test_extract_multi_nocase(dtype) -> None:
807 pat_str = r"(\w+)_Xy_(\d*)"
808 pat_re: str | bytes = (
809 pat_str if dtype == np.str_ else bytes(pat_str, encoding="UTF-8")
810 )
811 pat_compiled = re.compile(pat_re, flags=re.IGNORECASE)
812
813 value = xr.DataArray(
814 [
815 ["a_Xy_0", "ab_xY_10-bab_Xy_110-baab_Xy_1100", "abc_Xy_01-cbc_Xy_2210"],
816 [
817 "abcd_Xy_-dcd_Xy_33210-dccd_Xy_332210",
818 "",
819 "abcdef_Xy_101-fef_Xy_5543210",
820 ],
821 ],
822 dims=["X", "Y"],
823 ).astype(dtype)
824
825 expected = xr.DataArray(
826 [
827 [["a", "0"], ["ab", "10"], ["abc", "01"]],
828 [["abcd", ""], ["", ""], ["abcdef", "101"]],
829 ],
830 dims=["X", "Y", "XX"],
831 ).astype(dtype)
832
833 res_str = value.str.extract(pat=pat_str, dim="XX", case=False)
834 res_re = value.str.extract(pat=pat_compiled, dim="XX")
835
836 assert res_str.dtype == expected.dtype
837 assert res_re.dtype == expected.dtype
838
839 assert_equal(res_str, expected)
840 assert_equal(res_re, expected)
841
842
843def test_extract_broadcast(dtype) -> None:

Callers

nothing calls this directly

Calls 3

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