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

Fix sort with unused levels #273

Merged
merged 2 commits into from
May 19, 2020
Merged

Fix sort with unused levels #273

merged 2 commits into from
May 19, 2020

Conversation

nalimilan
Copy link
Member

The code did not handle correctly the case when unused levels were present at the front.
This seems to have become easier to trigger since the index vs. levels distinction was dropped.

Fixes #269.

The code did not handle correctly the case when unused levels were present at the front.
This seems to have become easier to trigger since the index vs. levels distinction
was dropped.
src/array.jl Outdated
perm = sortperm(view(index, seen), order=ord)
nzcounts = counts[seen]
levs = eltype(v) >: Missing ? [missing; v.pool.valindex] : v.pool.valindex
sortedlevs = sort(Vector(view(levs, seen)), order=ord)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use? sort!(levs[seen], order=ord)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a Vector to avoid calling ourselves and getting a stack overflow. But yes sort! should work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

levs[seen] would create a new vector anyway - right? But this is minor I guess so it can stay as is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually there's a weird behavior which creates a CategoricalVector with logical indexing. Need to investigate that...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so tricky that I ended up filing a design issue against Base: JuliaLang/julia#36106.

src/array.jl Show resolved Hide resolved
@nalimilan nalimilan merged commit 3fb5245 into master May 19, 2020
@nalimilan nalimilan deleted the nl/sort branch May 19, 2020 15:38
This pull request was closed.
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 this pull request may close these issues.

Unexpected behaviour using sort
2 participants