<h4 dir="auto">Describe the workflow you want to enable</h4>
<p dir="auto">In some cases you need to use OrdinalEncoder even if the dataframe contains NaN, which couldn't be done at current sklearn version. For instance, when using KNNImputer to deal with missing values you need first change categorical columns into numerical, otherwise it couldn't be done. But when using OrdinalEncoder to change categorical columns into numerical, it requires the dataframe contains no NaN. So I have to impute first. See? it's head bites it's tail, couldn't be done. I'm new to it so not sure if I'm think right.</p>
<h4 dir="auto">Solution</h4>
<p dir="auto">Add  "ignore_nan" parameter to it. When "ignore_nan=True" it passthrough the nan without changing it. When it's False it throws an error.</p>
<h4 dir="auto">Describe alternatives you've considered, if relevant</h4>
<p dir="auto">Also with LabelEncoder.</p>
<p dir="auto">We should allow NaNs to pass-through in <code class="notranslate">OrdinalEncoder</code>. One reason is for supporting categorical features with NaNs in the <code class="notranslate">HistGradientBoosting </code> estimators:</p>
<p dir="auto">For the native categorical support, we require categories to be encoded as done by <code class="notranslate">OrdinalEncoder</code>. Yet,  <code class="notranslate">OrdinalEncoder</code> is unable to be fitted with NaNs. So we can't use the native categorical support of the Hist-GBDT if the categorical features have NaNs... Which is ironic because we do support NaNs as a native category in the Hist-GBDT code.</p>
<p dir="auto">In terms of API, we'd need a new <code class="notranslate">handle_missing={'error', 'passthrough'}</code> parameter which would default to 'error'.</p>
<p dir="auto">CC <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/ogrisel/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/ogrisel">@ogrisel</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/lorentzenchr/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/lorentzenchr">@lorentzenchr</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/thomasjpfan/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/thomasjpfan">@thomasjpfan</a></p>
<p dir="auto">(Note: This is a subset of the feature request from <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="611928957" data-permission-text="Title is private" data-url="https://github.com/scikit-learn/scikit-learn/issues/17123" data-hovercard-type="issue" data-hovercard-url="/scikit-learn/scikit-learn/issues/17123/hovercard" href="https://github.com/scikit-learn/scikit-learn/issues/17123">#17123</a>)<br>
(Marking as "Hard" because anything encoding-related is usually a headache ;)  )</p>