(self, missing_value)
| 179 | missing_value=('', 'a', 'not in the array', None), |
| 180 | ) |
| 181 | def test_compare_to_str_array(self, missing_value): |
| 182 | strs = self.strs |
| 183 | shape = strs.shape |
| 184 | arr = LabelArray(strs, missing_value=missing_value) |
| 185 | |
| 186 | if missing_value is None: |
| 187 | # As of numpy 1.9.2, object array != None returns just False |
| 188 | # instead of an array, with a deprecation warning saying the |
| 189 | # behavior will change in the future. Work around that by just |
| 190 | # using the ufunc. |
| 191 | notmissing = np.not_equal(strs, missing_value) |
| 192 | else: |
| 193 | notmissing = (strs != missing_value) |
| 194 | |
| 195 | check_arrays(arr.not_missing(), notmissing) |
| 196 | check_arrays(arr.is_missing(), ~notmissing) |
| 197 | |
| 198 | # The arrays are equal everywhere, but comparisons against the |
| 199 | # missing_value should always produce False |
| 200 | check_arrays(strs == arr, notmissing) |
| 201 | check_arrays(strs != arr, np.zeros_like(strs, dtype=bool)) |
| 202 | |
| 203 | def broadcastable_row(value, dtype): |
| 204 | return np.full((shape[0], 1), value, dtype=strs.dtype) |
| 205 | |
| 206 | def broadcastable_col(value, dtype): |
| 207 | return np.full((1, shape[1]), value, dtype=strs.dtype) |
| 208 | |
| 209 | # Test comparison between arr and a like-shap 2D array, a column |
| 210 | # vector, and a row vector. |
| 211 | for comparator, dtype, value in product((eq, ne), |
| 212 | (bytes, unicode, object), |
| 213 | set(self.rowvalues)): |
| 214 | check_arrays( |
| 215 | comparator(arr, np.full_like(strs, value)), |
| 216 | comparator(strs, value) & notmissing, |
| 217 | ) |
| 218 | check_arrays( |
| 219 | comparator(arr, broadcastable_row(value, dtype=dtype)), |
| 220 | comparator(strs, value) & notmissing, |
| 221 | ) |
| 222 | check_arrays( |
| 223 | comparator(arr, broadcastable_col(value, dtype=dtype)), |
| 224 | comparator(strs, value) & notmissing, |
| 225 | ) |
| 226 | |
| 227 | @parameter_space( |
| 228 | __fail_fast=True, |
nothing calls this directly
no test coverage detected