Chapter 9 - Lesson 6 - CategoricalDtype

Im trying the code for Chapter 9 - Lesson 6 and the line:

to = TabularPandas(df, procs, cat, cont, y_names=dep_var, splits=splits)

produces the following error:

File /opt/conda/lib/python3.10/site-packages/fastai/data/transforms.py:225, in CategoryMap.init(self, col, sort, add_na, strict)
224 def init(self, col, sort=True, add_na=False, strict=False):
→ 225 if hasattr(col, ‘dtype’) and isinstance(col.dtype, CategoricalDtype):
226 items = L(col.cat.categories, use_list=True)
227 #Remove non-used categories while keeping order

NameError: name ‘CategoricalDtype’ is not defined

I don’t know how to get around this. Has anyone else run into this?


!pip list | grep “fast|numpy|pandas”

fastai 2.7.14
fastapi 0.108.0
fastavro 1.9.3
fastcore 1.5.29
fastdownload 0.0.7
fasteners 0.19
fastjsonschema 2.19.1
fastprogress 1.0.3
fasttext 0.9.2
geopandas 0.14.3
msgpack-numpy 0.4.8
numpy 1.26.4
pandas 2.2.1
pandas-datareader 0.10.0
pandas-profiling 3.6.6
pandas-summary 0.2.0
pandasql 0.7.3
sklearn-pandas 2.2.0