Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unique() returns levels, not the CategoricalArray #357

Open
alyst opened this issue Jun 23, 2021 · 2 comments · May be fixed by #358
Open

unique() returns levels, not the CategoricalArray #357

alyst opened this issue Jun 23, 2021 · 2 comments · May be fixed by #358

Comments

@alyst
Copy link
Contributor

alyst commented Jun 23, 2021

It's strange that I have realized it only now, but unique(v::CategoricalArray{S}) returns Vector{S}, and not the categorical array of the same type as v.
Should it actually preserve the type of v to conform to the Base.unique() definition?

Otherwise some user code that should work regardless of the vector type (e.g. Vector{String} or CategoricalVector{String}) produces errors.

@bkamins
Copy link
Member

bkamins commented Jun 23, 2021

This is consistent with the docstring of unique for CategoricalArray:

Return levels which appear in A in their order of appearance. This function is significantly slower than levels since it needs to check whether levels are used or not.

However, indeed, it is strange and I would also expect CategoricalArray.

@alyst alyst linked a pull request Jun 23, 2021 that will close this issue
@nalimilan
Copy link
Member

See previous discussion at #129. The current behavior of unique is indeed a bit strange, but can you show in what cases it's a problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants