Categorical: let unique only return used categories
Merge pull request #8937 from JanSchulz/cat_unique2

Categorical: let unique only return used categories