TypeError: 'list' object is not callable with Categorify

I’m using Categorify to handle categorical data and TabularPandas to create train and test sets, the lines below work nicely.

procs = [Categorify]
to = TabularPandas(data, procs, cat_names, y_names=dep_var, splits=splits)

To use my model and get predictions for new rows that my model has not seen I need to transform categorical data appropriately (this is the only transform needed). So I try tabular.transform | fastai

tfm = Categorify(cat_names)
tfm(df)

and get TypeError

TypeError: 'list' object is not callable

How can I fix this?

Seems like you’ve shadowed the builtin name list pointing at a class by the same name pointing at its instance. Here is an example:

>>> example = list('easyhoss')  # here `list` refers to the builtin class
>>> list = list('abc')  # we create a variable `list` referencing an instance of `list`
>>> example = list('easyhoss')  # here `list` refers to the instance
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: 'list' object is not callable

I believe this is fairly obvious. Python stores object names (functions and classes are objects, too) in namespaces (which are implemented as dictionaries), hence you can rewrite pretty much any name in any scope. It won’t show up as an error of some sort. As you might know, Python emphasizes that “special cases aren’t special enough to break the rules”.

@Jesus489 , thank you!! In my case cat_names is a list of categorical columns, like
cat_names = ['cat_name1', 'cat_name2', 'cat_namen']
And I don’t see shadowed builtin name.