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

Function test_extract_multi_case

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

Source from the content-addressed store, hash-verified

764
765
766def test_extract_multi_case(dtype) -> None:
767 pat_str = r"(\w+)_Xy_(\d*)"
768 pat_re: str | bytes = (
769 pat_str if dtype == np.str_ else bytes(pat_str, encoding="UTF-8")
770 )
771 pat_compiled = re.compile(pat_re)
772
773 value = xr.DataArray(
774 [
775 ["a_Xy_0", "ab_xY_10-bab_Xy_110-baab_Xy_1100", "abc_Xy_01-cbc_Xy_2210"],
776 [
777 "abcd_Xy_-dcd_Xy_33210-dccd_Xy_332210",
778 "",
779 "abcdef_Xy_101-fef_Xy_5543210",
780 ],
781 ],
782 dims=["X", "Y"],
783 ).astype(dtype)
784
785 expected = xr.DataArray(
786 [
787 [["a", "0"], ["bab", "110"], ["abc", "01"]],
788 [["abcd", ""], ["", ""], ["abcdef", "101"]],
789 ],
790 dims=["X", "Y", "XX"],
791 ).astype(dtype)
792
793 res_str = value.str.extract(pat=pat_str, dim="XX")
794 res_re = value.str.extract(pat=pat_compiled, dim="XX")
795 res_str_case = value.str.extract(pat=pat_str, dim="XX", case=True)
796
797 assert res_str.dtype == expected.dtype
798 assert res_re.dtype == expected.dtype
799 assert res_str_case.dtype == expected.dtype
800
801 assert_equal(res_str, expected)
802 assert_equal(res_re, expected)
803 assert_equal(res_str_case, expected)
804
805
806def test_extract_multi_nocase(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…