Does label encoding an entire dataset cause data leakage?
The cleanest solution would be to apply scikit's OneHotEncoder with the handle_unknown parameter set to &quot;ignore&quot;:

handle_unknown{‘error’, ‘ignore’}, default=’error’
Whether to raise an error or ignore if an unknown categorical feature is present during transform (default is to raise). When this parameter is set to ‘ignore’ and an unknown category is encountered during transform, the resulting one-hot encoded columns for this feature will be all zeros. In the inverse transform, an unknown category will be denoted as None.

Other manual solution are described in this and this question on Stackoverflow, for example.