Why does VSCode say there is a problem in this code?

I created a file with the exact contents below. It runs fine, but VSCode keeps listing the file and the line with the select statement in the Problems tab.

Three questions:

  1. What is the problem?
    My guess is that it is related to the function delcol having no information about the columns of its argument. But this is not clear.

  2. How can I find what is the problem? (I tried)

  3. How do I stop VSCode from listing this as a Problem, given that the code runs fine?

using DataFrames
df = DataFrame(A = [1,2,3], B = [4,5,6], C = ["C", "D", "E"])

function delcol(df1)
    select(df1, Not([:A]))
end 

delcol(df)

Have you tried looking in the “Problem” tab of the terminal?

image

no problems are reported for me

(fwiw, this is probably just an MWE, but that function seems a bit superfluous?)

It was in the Problems tab that I saw there was a problem. It says there:

Possible method call error. Julia[4, 17]

I need to be able to delete a column of a DataFrame that was defined outside of a function. The function delcol does that, but I get the message above. It would be best to eliminate it.

There are other ways of deleting a column. For example, I could work with names(df), delete from it the undesired column name, and then call select with the shorter list of column names. I might end up going that way.

I thought it’s deleteat!(df::DataFrame, inds) now

According to the documentation in

Functions · DataFrames.jl (juliadata.org) "

deleteat deletes rows and inds must be: a vector of sorted and unique integers, a boolean vector, an integer, or Not wrapping any valid selector.

I want to use a symbol or a string to choose a column.

my bad, I think what you’re looking for is:
select!

Okay so there you have the problem - it’s a possible method call error. Of course in this case it isn’t an actual method call error, as the call signature select(::DataFrame, ::InvertedIndex) exists, so there’s a problem in how the Julia extension finds the method definitions for your code. Have you activated an environment that has DataFrames in it?

To answer your third question, you can disable this linter option in the extension settings:

And finally select! is indeed the way to remove a column from an existing DataFrame in place, I still don’t understand why you define a function that does nothing else than call the select function rather than just using the select function. Also you can do Not(:A), no need to create a one-element vector in the inverted index.

The package DataFrames is part of the environment.

Thanks for the info on disabling lint. I could not install package Lint, though:

(BW1) pkg> add Lint
    Updating registry at `C:\Users\fsald\.julia\registries\General`
    Updating git-repo `https://github.com/JuliaRegistries/General.git`
ERROR: The following package names could not be resolved:
 * Lint (not found in project, manifest or registry)

From inside Julia with Pkg.add("Lint") also did not work.

In my original code I have a function that receives a dataframe as an argument, removes a column from that dataframe, and adds newly calculated columns to that same dataframe. That function was quite complex, as it also performed other unrelated tasks. It wasn’t fit to be posted “as is,” since Julia Discourse’s guidelines ask for MWEs. For this reason I removed from it the unrelated tasks, trying to generate a MWE. What remained looked like a function that just wraps a select statement, which of course is not a very interesting function by itself.

But I assume the actual MWE in your code would have been

select(df, :A)

or not? Are there differences in the linter result between the function you defined and other calls to select?

Lint is not a package, linting is the process of running an automated code-checker to identify issues in your code. The Julia VSCode extension has in inbuilt linter, and the screenshot I shared was a screenshot taken from the Julia extension settings.

1 Like
function df_select_col(df)
    select(df, :C)
end

does not generate messages in the Problems tab, but

function delete_col(df)
    select(df, Not(:Col))
end

generates

Possible method call error. Julia[133, 16]

I looked further into the linter. I can toggle it on or off in settings.json or equivalently with Ctrl+Shift+P and choosing Julia: Toggle Linter. When I toggle off the linter the messages on the Problems tab disappear.

I could not figure out how to get to the screen with julia> Lint: Call you posted. Typing Lint: Call or even just Lint on a julia> prompt generates an error message.

Thanks for the help.

Okay so it looks like the problem is then with InvertedIndices not being correctly picked up - does the error go away if you add that explicitly to your environment or use it?

I ran into a similar issue a few weeks ago here: Linter misses `sort` method definition in `DataFrames` · Issue #2565 · julia-vscode/julia-vscode · GitHub

The linter options are just in the regular Julia extension settings, so press Ctrl+, to open settings and then type julia lint to bring up all the Julia extension linter settings.

I added InvertedIndices to the environment, restarted VSCode and the entry in the Problems tab is still there, whether I run the program from VSCode (clicking on an triangular arrow on the upper right of my screen) or by cutting and pasting in a REPL started from Powershell (inside VSCode) by typing julia.