joshday / OnlineStats.jl

⚡ Single-pass algorithms for statistics
https://joshday.github.io/OnlineStats.jl/latest/
MIT License
831 stars 62 forks source link

Bug: Counter T does not work with abstract types like Any #242

Closed schlichtanders closed 2 years ago

schlichtanders commented 2 years ago

Using Counter I was very surprised that Counter(Any) does not work.

Given the documentation Count the number of items in a data stream with elements of type T. this sounds like a but, as every element is of type Any.

joshday commented 2 years ago

Could you clarify what doesn't work? I don't think I follow you.

julia> o = Counter(Any)
Counter: n=0 | value=0

julia> fit!(o, 1)
Counter: n=1 | value=1

julia> fit!(o, "hi")
Counter: n=2 | value=2
schlichtanders commented 2 years ago

Hi JoshDay, thank you for managing these tickets.

I actually found the misunderstanding

julia> o = Counter(Any)
Counter: n=0 | value=0

julia> fit!(o, [1,2,3,4])
Counter: n=1 | value=1

Any is also matching iterators, which makes totally sense. The workaround is iterating yourself.

joshday commented 2 years ago

Ah, right! Glad you worked it out.