yt.units.unit_object.Unit.count

Unit.count(query)

Count the number of matching subexpressions.