Are you sure this line of code raises the warning or are you using it somewhere else in your script as well (without the changes)?
I’m using a newer version without any warning:
>>> sklearn.__version__
'0.24.1'
>>> from sklearn.utils.class_weight import compute_class_weight
>>> import numpy as np
>>> targets = np.random.randint(0, 100, (100,))
>>> class_weights = compute_class_weight('balanced', classes=np.unique(targets), y=targets)
>>>

and even downgrading to 0.23.2 gives no warnings:
>>> sklearn.__version__
'0.23.2'
>>> from sklearn.utils.class_weight import compute_class_weight
>>> import numpy as np
>>> targets = np.random.randint(0, 100, (100,))
>>> class_weights = compute_class_weight('balanced', classes=np.unique(targets), y=targets)
>>>

If I don’t use the classes=... argument, I get your warning.