(dtype)
| 722 | |
| 723 | |
| 724 | def test_extract_single_nocase(dtype) -> None: |
| 725 | pat_str = r"(\w+)?_Xy_\d*" |
| 726 | pat_re: str | bytes = ( |
| 727 | pat_str if dtype == np.str_ else bytes(pat_str, encoding="UTF-8") |
| 728 | ) |
| 729 | pat_compiled = re.compile(pat_re, flags=re.IGNORECASE) |
| 730 | |
| 731 | value = xr.DataArray( |
| 732 | [ |
| 733 | ["a_Xy_0", "ab_xY_10-bab_Xy_110-baab_Xy_1100", "abc_Xy_01-cbc_Xy_2210"], |
| 734 | [ |
| 735 | "abcd_Xy_-dcd_Xy_33210-dccd_Xy_332210", |
| 736 | "_Xy_1", |
| 737 | "abcdef_Xy_101-fef_Xy_5543210", |
| 738 | ], |
| 739 | ], |
| 740 | dims=["X", "Y"], |
| 741 | ).astype(dtype) |
| 742 | |
| 743 | targ_none = xr.DataArray( |
| 744 | [["a", "ab", "abc"], ["abcd", "", "abcdef"]], dims=["X", "Y"] |
| 745 | ).astype(dtype) |
| 746 | targ_dim = xr.DataArray( |
| 747 | [[["a"], ["ab"], ["abc"]], [["abcd"], [""], ["abcdef"]]], dims=["X", "Y", "XX"] |
| 748 | ).astype(dtype) |
| 749 | |
| 750 | res_str_none = value.str.extract(pat=pat_str, dim=None, case=False) |
| 751 | res_str_dim = value.str.extract(pat=pat_str, dim="XX", case=False) |
| 752 | res_re_none = value.str.extract(pat=pat_compiled, dim=None) |
| 753 | res_re_dim = value.str.extract(pat=pat_compiled, dim="XX") |
| 754 | |
| 755 | assert res_re_dim.dtype == targ_none.dtype |
| 756 | assert res_str_dim.dtype == targ_dim.dtype |
| 757 | assert res_re_none.dtype == targ_none.dtype |
| 758 | assert res_re_dim.dtype == targ_dim.dtype |
| 759 | |
| 760 | assert_equal(res_str_none, targ_none) |
| 761 | assert_equal(res_str_dim, targ_dim) |
| 762 | assert_equal(res_re_none, targ_none) |
| 763 | assert_equal(res_re_dim, targ_dim) |
| 764 | |
| 765 | |
| 766 | def test_extract_multi_case(dtype) -> None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…