Skip to content

Make sure that new CategoricalArray allocates new pool and refs #110

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

Merged
merged 4 commits into from
Dec 13, 2017
Merged

Make sure that new CategoricalArray allocates new pool and refs #110

merged 4 commits into from
Dec 13, 2017

Conversation

bkamins
Copy link
Member

@bkamins bkamins commented Dec 11, 2017

Following Issue #107.
I test for new refs and new pool separately as I guess it is safest.

@bkamins
Copy link
Member Author

bkamins commented Dec 11, 2017

@nalimilan similarly here - errors are unrelated (due to changes in 0.7)

Copy link
Member

@nalimilan nalimilan left a comment

Choose a reason for hiding this comment

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

Thanks!

src/array.jl Outdated
@@ -154,14 +154,23 @@ CategoricalMatrix{T}(m::Int, n::Int; ordered=false) where {T} =

## Constructors from arrays

# This method is needed to ensure that a copy of the pool is always made
# This method is needed to ensure that a copy of the refs and pool is always made
# so that ordered!() does not affect the original array
Copy link
Member

Choose a reason for hiding this comment

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

Just remove this line, now we make a copy because that's what the function is documented to do.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

src/array.jl Outdated
needs_copy = true
end
if needs_copy
res = CategoricalArray{V, N}(refs, pool)
Copy link
Member

Choose a reason for hiding this comment

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

Better always call that constructor, anyway CategoricalArray is an immutable and it should be cheap.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

test/11_array.jl Outdated
@@ -638,4 +638,14 @@ end
@test unique(x) == collect(1500:-1:1)
end

@testset "categorical() makes a copy of pool and refs" begin
Copy link
Member

Choose a reason for hiding this comment

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

Put this in arraycommon.jl instead. It would make sense to test with an array supporting missing too, and with the CategoricalArray{T, R} form with equal and different types, just in case.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

test/11_array.jl Outdated
@testset "categorical() makes a copy of pool and refs" begin
x = categorical(1:10)
y = categorical(x)
@test !(x.refs === y.refs)
Copy link
Member

Choose a reason for hiding this comment

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

Use !==.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

nalimilan
nalimilan previously approved these changes Dec 12, 2017
src/array.jl Outdated
function CategoricalArray{T, N, R}(A::CategoricalArray{S, N, Q};
ordered=_isordered(A)) where {S, T, N, Q, R}
V = unwrap_catvaluetype(T)
res = convert(CategoricalArray{V, N, R}, A)
if res.pool === A.pool # convert() only makes a copy when necessary
res = CategoricalArray{V, N}(res.refs, deepcopy(res.pool))
needs_copy = false
Copy link
Member

Choose a reason for hiding this comment

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

needs_copy is no longer needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@JuliaData JuliaData deleted a comment from codecov bot Dec 12, 2017
@JuliaData JuliaData deleted a comment from codecov bot Dec 12, 2017
@nalimilan nalimilan dismissed their stale review December 12, 2017 09:37

Check the wrong button.

@codecov
Copy link

codecov bot commented Dec 12, 2017

Codecov Report

Merging #110 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #110      +/-   ##
==========================================
+ Coverage   97.78%   97.81%   +0.02%     
==========================================
  Files           9        9              
  Lines         678      685       +7     
==========================================
+ Hits          663      670       +7     
  Misses         15       15
Impacted Files Coverage Δ
src/array.jl 97.35% <100%> (+0.07%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8207ff7...3102ce5. Read the comment docs.

Copy link
Contributor

@cjprybol cjprybol left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!

@nalimilan nalimilan merged commit 76e1d1c into JuliaData:master Dec 13, 2017
@bkamins bkamins deleted the copy_on_creation branch December 13, 2017 22:31
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.

3 participants