Not always the syntax a.b calls getfield(a, :b)?

Perhaps it is not a question strictly pertinent to the context of dataframes, but it arose from me thinking about a problem posed here in the data section of slack forum
I tried to use the syntax k.rownumber instead of getfield (k,: rownumber) and it didn’t work in the sense that “k.” searched for column k.rownumber and not field k.rownumber.
I have no concrete interest in the matter, I would just like to understand (if it’s not too complicated) how things go: why, in this case, the syntax with the “.” is looking for the column and not the field?

I believe it just depends on whether the table you are working with implements the column table or row table interface of Tables.jl. Most data packages implement the column table specification, so those calls operate by selecting columns rather than rows.

1 Like

Just to check, do you know that the dot syntax calls getproperty, not getfield, right? getproperty then calls getfield but only if it was not overloaded for the specific type to have another behavior. See: Essentials · The Julia Language

8 Likes

Hi @Henrique_Becker.
Clear and complete explanation for the general aspects of the dot syntax, thank you very much.

Could you, by chance, direct me to the source code in dataframes where this specific behavior of the getproperty function is defined?

1 Like

Direct yourself:

julia> using DataFrames

julia> df = DataFrame(a = rand(5));

julia> @which df.a
getproperty(df::AbstractDataFrame, col_ind::Symbol) in DataFrames at /home/nils/.julia/packages/DataFrames/nxjiD/src/abstractdataframe/abstractdataframe.jl:356

6 Likes

Yea and I guess this disproves my earlier post, as that is actually separate from the Tables.jl compatibility code. So this is related just to the design decision of the package to be columnar oriented (so naturally they eventually implement the ColumnTable stuff from Tables.jl).

2 Likes

This is a decision of a package design to provide a syntax similar to NamedTuple or structs, as it is cleanest to type and read.

3 Likes