Pandas bracket assignment getitem/setattr

I'm curious how the actual pandas getattr and setattr functionality works under the hood

import pandas
df = pandas.DataFrame([1,2,3])

df['test'] # throws a KeyError
df['test'] = 1  # no error

It looks like some combination of getitem and setattr are being used in the assignment line df['test'] = 1. Can anyone generally explain how the flow works here - I don't really understand how getitem and setattr are used in conjunction here that is able to assign a new column

I would think df['test'] returns some type of assignment object which has a setattr hook but that doesn't seem like the case


From looking at the source code it looks like the __getattribute__ hook is being used, which is different from __getattr__. Still not quite sure the underlying logic after looking at source


I put some print statements in the pandas source code and it looks like __getitem__ and __setattr__ aren't being called in the df['test'] = 1 line of code. Perhaps the DataFrame class inherits from dict?