-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement copy(::CategoricalArray) and use it instead of deepcopy
`deepcopy` is not recommended and it is very slow, especially when there are many levels. This has a significant impact on `setindex!`.
- Loading branch information
Showing
8 changed files
with
73 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module TestCopy | ||
using Test | ||
using CategoricalArrays | ||
using CategoricalArrays: CategoricalPool, catvalue | ||
|
||
@testset "copy" begin | ||
pool = CategoricalPool(["d", "c", "b"]) | ||
ordered!(pool, true) | ||
pool2 = copy(pool) | ||
|
||
@test length(pool2) == 3 | ||
@test pool2.levels == pool2.index == ["d", "c", "b"] | ||
@test pool2.invindex == Dict("d"=>1, "c"=>2, "b"=>3) | ||
@test pool2.order == 1:3 | ||
@test pool2.valindex == [catvalue(i, pool2) for i in 1:3] | ||
@test pool2.ordered | ||
|
||
levels!(pool2, ["a", "b", "c", "d"]) | ||
ordered!(pool2, false) | ||
|
||
@test length(pool) == 3 | ||
@test pool.levels == pool.index == ["d", "c", "b"] | ||
@test pool.invindex == Dict("d"=>1, "c"=>2, "b"=>3) | ||
@test pool.order == 1:3 | ||
@test pool.valindex == [catvalue(i, pool) for i in 1:3] | ||
@test pool.ordered | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters