Test that categories are inferred in sorted order if they're not explicitly passed.
(self)
| 249 | self.assertIs(sliced.missing_value, arr.missing_value) |
| 250 | |
| 251 | def test_infer_categories(self): |
| 252 | """ |
| 253 | Test that categories are inferred in sorted order if they're not |
| 254 | explicitly passed. |
| 255 | """ |
| 256 | arr1d = LabelArray(self.strs, missing_value='') |
| 257 | codes1d = arr1d.as_int_array() |
| 258 | self.assertEqual(arr1d.shape, self.strs.shape) |
| 259 | self.assertEqual(arr1d.shape, codes1d.shape) |
| 260 | |
| 261 | categories = arr1d.categories |
| 262 | unique_rowvalues = set(self.rowvalues) |
| 263 | |
| 264 | # There should be an entry in categories for each unique row value, and |
| 265 | # each integer stored in the data array should be an index into |
| 266 | # categories. |
| 267 | self.assertEqual(list(categories), sorted(set(self.rowvalues))) |
| 268 | self.assertEqual( |
| 269 | set(codes1d.ravel()), |
| 270 | set(range(len(unique_rowvalues))) |
| 271 | ) |
| 272 | for idx, value in enumerate(arr1d.categories): |
| 273 | check_arrays( |
| 274 | self.strs == value, |
| 275 | arr1d.as_int_array() == idx, |
| 276 | ) |
| 277 | |
| 278 | # It should be equivalent to pass the same set of categories manually. |
| 279 | arr1d_explicit_categories = LabelArray( |
| 280 | self.strs, |
| 281 | missing_value='', |
| 282 | categories=arr1d.categories, |
| 283 | ) |
| 284 | check_arrays(arr1d, arr1d_explicit_categories) |
| 285 | |
| 286 | for shape in (9, 3), (3, 9), (3, 3, 3): |
| 287 | strs2d = self.strs.reshape(shape) |
| 288 | arr2d = LabelArray(strs2d, missing_value='') |
| 289 | codes2d = arr2d.as_int_array() |
| 290 | |
| 291 | self.assertEqual(arr2d.shape, shape) |
| 292 | check_arrays(arr2d.categories, categories) |
| 293 | |
| 294 | for idx, value in enumerate(arr2d.categories): |
| 295 | check_arrays(strs2d == value, codes2d == idx) |
| 296 | |
| 297 | def test_reject_ufuncs(self): |
| 298 | """ |
nothing calls this directly
no test coverage detected