joshday / OnlineStats.jl

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

Julia VS Code extension reports "Possible method call error" for `fit!` #268

Closed Yue-Zhengyuan closed 3 months ago

Yue-Zhengyuan commented 9 months ago

I write the following small program to ask input numbers from user, and calculate the mean and variance.

using OnlineStats

function calculate_average()
    o = Series(Mean(), Variance())
    println(typeof(o))
    i = 0
    while true
        println("Enter number or 'q' to quit:")
        input = readline()
        if input == "q"
            break
        else
            x = parse(Float64, input)
            fit!(o, x)
            i += 1
            println(value(o))
        end
    end
end

calculate_average()

But the Julia VS Code extension reports "Possible method call error" at fit!(o, x). It thinks fit! as StatsAPI.fit!, and reports it is a "function with 0 methods"


System information:

joshday commented 9 months ago

My system looks just like yours, but I can't reproduce this.

Yue-Zhengyuan commented 9 months ago

Here are the packages I installed. I wonder if any of them interferes with the VS Code extension.

(@v1.9) pkg> status
Status `~/.julia/environments/v1.9/Project.toml`
  [c7e460c6] ArgParse v1.1.4
  [6e4b80f9] BenchmarkTools v1.3.2
  [d360d2e6] ChainRulesCore v1.18.0
  [8a292aeb] Cuba v2.3.0
  [864edb3b] DataStructures v0.18.15
  [cc61a311] FLoops v0.2.1
  [6a86dc24] FiniteDiff v2.21.1
  [92c85e6c] GSL v1.0.1
  [7073ff75] IJulia v1.24.2
  [c8e1da08] IterTools v1.8.0
  [033835bb] JLD2 v0.4.38
  [682c06a0] JSON v0.21.4
  [0b1a1467] KrylovKit v0.6.0
  [b964fa9f] LaTeXStrings v1.3.1
  [8fca5bbe] MultiQuad v1.3.1
  [15e1cf62] NPZ v0.4.3
  [ebe7aa44] OMEinsum v0.7.5
  [5fb14364] OhMyREPL v0.5.23
  [a15396b6] OnlineStats v1.6.3
  [429524aa] Optim v1.7.8
⌃ [bac558e1] OrderedCollections v1.6.2
  [d96e819e] Parameters v0.12.3
⌃ [e0809bc7] Permanents v0.1.1
  [49802e3a] ProgressBars v1.5.1
  [438e738f] PyCall v1.96.2
  [d330b81b] PyPlot v2.11.2
  [2913bbd2] StatsBase v0.34.2
  [07d1fe3e] TensorKit v0.12.0
  [6aa20fa7] TensorOperations v4.0.7
  [3a884ed6] UnPack v1.0.2
  [e88e6eb3] Zygote v0.6.67
adknudson commented 5 months ago

I often run into a similar issue, and can fix it by explicitly importing the fit! method

using OnlineStats
using OnlineStats: fit!

I think the issue usually comes from using extended methods, i.e. because fit! is imported/owned by StatsBase. Seems to be a general limitation of the VSCode extension.