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

ready Accumulator for v1.0 #837

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

ready Accumulator for v1.0 #837

wants to merge 2 commits into from

Conversation

oxinabox
Copy link
Member

checks off accumulator.jl on #479

One thing I am not sure about is the names nlargest and nsmallest
those could be changed

src/accumulator.jl Outdated Show resolved Hide resolved
Arguably we should just leave this as an ambig error but probably people want it resolved this way
Copy link
Contributor

@Krastanov Krastanov left a comment

Choose a reason for hiding this comment

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

Hi, folks,

given that I depend on this package, I tried to give a bit back by reviewing. Please feel free to disregard if the community standards permit only reviews from vetted individuals.

The changes look good to me. I had some minor concerns about pop!, which behaves a bit surprisingly to me, but it seems self-consistent. Maybe Counter and Accumulator have different behavior for their pop! in which case everything is fine.

LGTM, but please let me know how I should understand pop!

@@ -92,7 +90,9 @@ Decrements the count for `x` by `v` (defaulting to one)
dec!(ct::Accumulator, x, v::Number) = (ct[x] -= v)
dec!(ct::Accumulator{T,V}, x) where {T,V} = dec!(ct, x, one(V))

#TODO: once we are done deprecating `pop!` for `reset!` then add `pop!` as an alias for `dec!`
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume it was decided at some point that pop! is not being deprecated so this TODO is incorrect and that is why it is deleted and disobeyed?

Copy link
Contributor

Choose a reason for hiding this comment

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

When pop! becomes an alias for dec! as seen here, then this will be happening:

julia> a = Accumulator(:k=>1); dec!(a, :k); dec!(a, :k)
-1

Just making sure that this is the desired behavior. Asking because I would have expected KeyError when the count goes negative.

@@ -92,7 +90,9 @@ Decrements the count for `x` by `v` (defaulting to one)
dec!(ct::Accumulator, x, v::Number) = (ct[x] -= v)
dec!(ct::Accumulator{T,V}, x) where {T,V} = dec!(ct, x, one(V))

#TODO: once we are done deprecating `pop!` for `reset!` then add `pop!` as an alias for `dec!`
Base.pop!(ct::Accumulator, x) = dec!(ct, x)
Base.pop!(ct::Accumulator, x, default) = haskey(ct, x) ? dec!(ct, x) : default
Copy link
Contributor

Choose a reason for hiding this comment

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

similarly to what I mentioned above, here I would have expected checking for "value equal zero", not only "has key"

@Krastanov
Copy link
Contributor

In #479 (comment) there is an admonition to not use push!(container, key, value), but here it says # inc! is preferred over push!, but we need to provide push! for the Bag interpreation. Just putting it out here in case this contradiction is important.

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