(self, variant, unit, error, dtype)
| 2899 | ), |
| 2900 | ) |
| 2901 | def test_where(self, variant, unit, error, dtype): |
| 2902 | original_unit = unit_registry.m |
| 2903 | array = np.linspace(0, 1, 10).astype(dtype) * original_unit |
| 2904 | |
| 2905 | data_array = xr.DataArray(data=array) |
| 2906 | |
| 2907 | condition = data_array < 0.5 * original_unit |
| 2908 | other = np.linspace(-2, -1, 10).astype(dtype) * unit |
| 2909 | variant_kwargs = { |
| 2910 | "masking": {"cond": condition}, |
| 2911 | "replacing_scalar": {"cond": condition, "other": -1 * unit}, |
| 2912 | "replacing_array": {"cond": condition, "other": other}, |
| 2913 | "dropping": {"cond": condition, "drop": True}, |
| 2914 | } |
| 2915 | kwargs = variant_kwargs[variant] |
| 2916 | kwargs_without_units = { |
| 2917 | key: strip_units( |
| 2918 | convert_units( |
| 2919 | value, {None: original_unit if array.check(unit) else None} |
| 2920 | ) |
| 2921 | ) |
| 2922 | for key, value in kwargs.items() |
| 2923 | } |
| 2924 | |
| 2925 | if variant not in ("masking", "dropping") and error is not None: |
| 2926 | with pytest.raises(error): |
| 2927 | data_array.where(**kwargs) |
| 2928 | |
| 2929 | return |
| 2930 | |
| 2931 | expected = attach_units( |
| 2932 | strip_units(data_array).where(**kwargs_without_units), |
| 2933 | extract_units(data_array), |
| 2934 | ) |
| 2935 | actual = data_array.where(**kwargs) |
| 2936 | |
| 2937 | assert_units_equal(expected, actual) |
| 2938 | assert_identical(expected, actual) |
| 2939 | |
| 2940 | @pytest.mark.xfail(reason="uses numpy.vectorize") |
| 2941 | def test_interpolate_na(self): |
nothing calls this directly
no test coverage detected