<p dir="auto">Assume you want to evaluate or grid search the parameters of the following pipeline</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from sklearn.preprocessing import Imputer
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import Pipeline

p = Pipeline([
    ('imputer', Imputer(strategy='media', missing_values='NaN')),
    ('classifier', LogisticRegression(C=1)),
])"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">sklearn</span>.<span class="pl-s1">preprocessing</span> <span class="pl-k">import</span> <span class="pl-v">Imputer</span>
<span class="pl-k">from</span> <span class="pl-s1">sklearn</span>.<span class="pl-s1">linear_model</span> <span class="pl-k">import</span> <span class="pl-v">LogisticRegression</span>
<span class="pl-k">from</span> <span class="pl-s1">sklearn</span>.<span class="pl-s1">pipeline</span> <span class="pl-k">import</span> <span class="pl-v">Pipeline</span>

<span class="pl-s1">p</span> <span class="pl-c1">=</span> <span class="pl-v">Pipeline</span>([
    (<span class="pl-s">'imputer'</span>, <span class="pl-v">Imputer</span>(<span class="pl-s1">strategy</span><span class="pl-c1">=</span><span class="pl-s">'media'</span>, <span class="pl-s1">missing_values</span><span class="pl-c1">=</span><span class="pl-s">'NaN'</span>)),
    (<span class="pl-s">'classifier'</span>, <span class="pl-v">LogisticRegression</span>(<span class="pl-v">C</span><span class="pl-c1">=</span><span class="pl-c1">1</span>)),
])</pre></div>
<p dir="auto">At the moment it is not possible as the <code class="notranslate">cross_val_score</code> and <code class="notranslate">GridSearchCV</code> tools call <code class="notranslate">check_arrays</code> internally which raises an exception if there are <code class="notranslate">NaN</code> values in the data.</p>
<p dir="auto">I think we should add <code class="notranslate">allow_nans=False</code> parameter to <code class="notranslate">check_arrays</code>, <code class="notranslate">cross_val_score</code> and <code class="notranslate">GridSearchCV</code> to make it possible to the user to disable the check for nans and hence allow our imputing pipeline to work as expected.</p>
<p dir="auto">When <code class="notranslate">GridSearchCV</code> sees a NaN, it panics. This is annoying when the estimator is a pipeline that starts with an <code class="notranslate">Imputer</code>, as now the imputer must be trained outside of the grid search giving potentially skewed results.</p>