'Test that categories are inferred in sorted order if they\'re not
explicitly passed.'

def test_infer_categories(self):

    arr1d = LabelArray(self.strs, missing_value='')
    codes1d = arr1d.as_int_array()
    self.assertEqual(arr1d.shape, self.strs.shape)
    self.assertEqual(arr1d.shape, codes1d.shape)
    categories = arr1d.categories
    unique_rowvalues = set(self.rowvalues)
    self.assertEqual(list(categories), sorted(set(self.rowvalues)))
    self.assertEqual(set(codes1d.ravel()), set(range(len(unique_rowvalues))))
    for (idx, value) in enumerate(arr1d.categories):
        check_arrays((self.strs == value), (arr1d.as_int_array() == idx))
    arr1d_explicit_categories = LabelArray(self.strs, missing_value='', categories=arr1d.categories)
    check_arrays(arr1d, arr1d_explicit_categories)
    for shape in ((9, 3), (3, 9), (3, 3, 3)):
        strs2d = self.strs.reshape(shape)
        arr2d = LabelArray(strs2d, missing_value='')
        codes2d = arr2d.as_int_array()
        self.assertEqual(arr2d.shape, shape)
        check_arrays(arr2d.categories, categories)
        for (idx, value) in enumerate(arr2d.categories):
            check_arrays((strs2d == value), (codes2d == idx))
