(dtype)
| 674 | |
| 675 | |
| 676 | def test_extract_single_case(dtype) -> None: |
| 677 | pat_str = r"(\w+)_Xy_\d*" |
| 678 | pat_re: str | bytes = ( |
| 679 | pat_str if dtype == np.str_ else bytes(pat_str, encoding="UTF-8") |
| 680 | ) |
| 681 | pat_compiled = re.compile(pat_re) |
| 682 | |
| 683 | value = xr.DataArray( |
| 684 | [ |
| 685 | ["a_Xy_0", "ab_xY_10-bab_Xy_110-baab_Xy_1100", "abc_Xy_01-cbc_Xy_2210"], |
| 686 | [ |
| 687 | "abcd_Xy_-dcd_Xy_33210-dccd_Xy_332210", |
| 688 | "", |
| 689 | "abcdef_Xy_101-fef_Xy_5543210", |
| 690 | ], |
| 691 | ], |
| 692 | dims=["X", "Y"], |
| 693 | ).astype(dtype) |
| 694 | |
| 695 | targ_none = xr.DataArray( |
| 696 | [["a", "bab", "abc"], ["abcd", "", "abcdef"]], dims=["X", "Y"] |
| 697 | ).astype(dtype) |
| 698 | targ_dim = xr.DataArray( |
| 699 | [[["a"], ["bab"], ["abc"]], [["abcd"], [""], ["abcdef"]]], dims=["X", "Y", "XX"] |
| 700 | ).astype(dtype) |
| 701 | |
| 702 | res_str_none = value.str.extract(pat=pat_str, dim=None) |
| 703 | res_str_dim = value.str.extract(pat=pat_str, dim="XX") |
| 704 | res_str_none_case = value.str.extract(pat=pat_str, dim=None, case=True) |
| 705 | res_str_dim_case = value.str.extract(pat=pat_str, dim="XX", case=True) |
| 706 | res_re_none = value.str.extract(pat=pat_compiled, dim=None) |
| 707 | res_re_dim = value.str.extract(pat=pat_compiled, dim="XX") |
| 708 | |
| 709 | assert res_str_none.dtype == targ_none.dtype |
| 710 | assert res_str_dim.dtype == targ_dim.dtype |
| 711 | assert res_str_none_case.dtype == targ_none.dtype |
| 712 | assert res_str_dim_case.dtype == targ_dim.dtype |
| 713 | assert res_re_none.dtype == targ_none.dtype |
| 714 | assert res_re_dim.dtype == targ_dim.dtype |
| 715 | |
| 716 | assert_equal(res_str_none, targ_none) |
| 717 | assert_equal(res_str_dim, targ_dim) |
| 718 | assert_equal(res_str_none_case, targ_none) |
| 719 | assert_equal(res_str_dim_case, targ_dim) |
| 720 | assert_equal(res_re_none, targ_none) |
| 721 | assert_equal(res_re_dim, targ_dim) |
| 722 | |
| 723 | |
| 724 | def test_extract_single_nocase(dtype) -> None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…