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

**URL:** <https://discourse.julialang.org/t/not-always-the-syntax-a-b-calls-getfield-a-b/62549>\
**Category:** Data\
**Created:** [June 7, 2021, 10:03pm UTC](https://discourse.julialang.org/t/not-always-the-syntax-a-b-calls-getfield-a-b/62549 "2021-06-07T22:03:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [June 7, 2021, 10:03pm UTC](https://discourse.julialang.org/t/not-always-the-syntax-a-b-calls-getfield-a-b/62549/1 "2021-06-07T22:03:58Z")

</div>

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](https://app.slack.com/client/T68168MUP/C674VR0HH/thread/C674VR0HH-1623077757.226500)  
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?

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [June 7, 2021, 10:12pm UTC](https://discourse.julialang.org/t/not-always-the-syntax-a-b-calls-getfield-a-b/62549/3 "2021-06-07T22:12:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [June 7, 2021, 11:33pm UTC](https://discourse.julialang.org/t/not-always-the-syntax-a-b-calls-getfield-a-b/62549/4 "2021-06-07T23:33:50Z")

</div>

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](https://docs.julialang.org/en/v1/base/base/#Base.getproperty)

---

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [June 8, 2021, 7:10pm UTC](https://discourse.julialang.org/t/not-always-the-syntax-a-b-calls-getfield-a-b/62549/5 "2021-06-08T19:10:07Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [June 8, 2021, 7:12pm UTC](https://discourse.julialang.org/t/not-always-the-syntax-a-b-calls-getfield-a-b/62549/6 "2021-06-08T19:12:53Z")

</div>

Direct yourself:

```julia
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

```

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [June 8, 2021, 8:09pm UTC](https://discourse.julialang.org/t/not-always-the-syntax-a-b-calls-getfield-a-b/62549/7 "2021-06-08T20:09:40Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [June 8, 2021, 8:20pm UTC](https://discourse.julialang.org/t/not-always-the-syntax-a-b-calls-getfield-a-b/62549/8 "2021-06-08T20:20:13Z")

</div>

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