This code do not works anymore after julia 1.5.3 update

Hello, good day. I updated my environment to julia 1.5.3 and a lot of project I had stoped work.
This code do not works anymore. Someone knows why it stoped work?

setosa_df = iris[iris[:species] .== "setosa", :]

ERROR: LoadError: MethodError: no method matching getindex(::DataFrame, ::Symbol)

Was some interfaces broked in this update?

I don’t know the exact answer to your question, but this is probably related to a recent DataFrames update and not to the Julia update. What version of DataFrames are you using? The latest release was 0.22 and was breaking.

2 Likes

I was using that Installed DataFrames v0.22.0. There is a way to workaround tha issue?

I’ll ping @bkamins, he’ll confirm if this a DataFrames issue or something else. And he can help solving it.

EDIT: also @pdeffebach and @nalimilan could probably help.

Something like this should work, but definitely there were deprecation warnings in previous versions of DataFrames

setosa_df = iris[iris.species .== "setosa", :]
1 Like

It works. Seems dataframes is not indentifying :column symbols.

Hello Andrei,
I hadn’t this issue because I did a clean install. Deleted all that folders before install. The only issue was in the libraries.

ERROR: LoadError: MethodError: no method matching getindex(::DataFrame, ::Symbol)
Closest candidates are:
getindex(::DataFrame, ::Integer, ::Union{Signed, Unsigned})

Yes this syntax has been deprecated for years. Use df[rows, :] instead. You can go back to 0.21 and enable deprecation warnings to help porting your code.

3 Likes

I was thinking that using :symbols was the best option. Did not knew that it was deprecated.

You can use:

df.column
df."column"
df[:, :column]
df[:, "column"]
df[!, :column] # no copy version of df[:, :column]
df[!, "column"] # no copy version of df[:, "column"]

As @nalimilan commented:

df[:column]

has been deprecated for over a year. DataFrame is 2-dimensional not 1-dimensional.

5 Likes

An alternative way to write this is:

filter(:species => ==("setosa"), iris)
1 Like

The problem cames because that syntax is depredated from a time.

The solution is:

setosa_df = iris[iris[:, :species] .== "setosa", :]

or

setosa_df = iris[iris[!, :species] .== "setosa", :]

You can indicate or iris[:, :species], in that case you are using a copy. Another option is iris[!, :species] if you want to use a view.

Also you can use the new syntax (from 0.21):

setosa_df = filter(:species => ==("setosa"), iris)

it is more different, but it is a bit more readable in my opinion.

3 Likes

I’ll need update my knowlege about julia and dataframes. Thank you guys.