Question: )             else:                 kernel = self.kernel            y_mean = np.zeros(X.shape[0])            n_targets = self.n_targets if self.n_targets is not None else 1            y_mean = np.zeros(shape=(X.shape[0], n_targets)).squeeze()             if return_cov:                 y_cov = kernel(X)                if n_targets > 1:                    y_cov = np.repeat(                        np.expand_dims(y_cov, -1), repeats=n_targets, axis=-1                    )                 return y_mean, y_cov             elif return_std:                 y_var = kernel.diag(X)                if n_targets > 1:                    y_var = np.repeat(                        np.expand_dims(y_var, -1), repeats=n_targets, axis=-1                    )                 return y_mean, np.sqrt(y_var)             else:                 return y_mean


Question: import functools  import numpy as np<ins>from scipy.sparse import issparse</ins>  from ...utils import check_random_state from ...utils import check_X_y

[MRG] Fixes sklearn.metrics.silhouette_samples for sparse matrices <!-- Thanks for contributing a pull request! Please ensure you have taken a look at the contribution guidelines: -- The changes update the reduce function used for computing the intra-cluster and inter-cluster distances. The current version is failing at, a) the pre-computed check for sparse matrices while getting the diagonal elements b) when trying to index a sparse matrix to pass weights to np.bincount function <!-- Please be aware that we are a loose team of volunteers so patience is necessary; assistance handling other issues is very welcome. We value all user contributions, no matter how minor they are. If we are slow to review, either the pull request needs some benchmarking, tinkering, convincing, etc. or more likely the reviewers are simply busy. In either case, we ask for your understanding during the review process. For more information, see our FAQ on this topic: http://scikit- Thanks for contributing! --


Question: Parameters     ----------    D_chunk : array-like of shape (n_chunk_samples, n_samples)        Precomputed distances for a chunk.    D_chunk : {array-like, sparse matrix} of shape (n_chunk_samples, n_samples)        Precomputed distances for a chunk. If a sparse matrix is provided,        only CSR format is accepted.     start : int         First index in the chunk.     labels : array-like of shape (n_samples,)


Question: label_freqs : array-like         Distribution of cluster labels in ``labels``.     """    n_chunk_samples = D_chunk.shape[0]     # accumulate distances from each sample to each cluster    clust_dists = np.zeros((len(D_chunk), len(label_freqs)), dtype=D_chunk.dtype)    for i in range(len(D_chunk)):        clust_dists[i] += np.bincount(            labels, weights=D_chunk[i], minlength=len(label_freqs)        )    cluster_distances = np.zeros(        (n_chunk_samples, len(label_freqs)), dtype=D_chunk.dtype    )     # intra_index selects intra-cluster distances within clust_dists    intra_index = (np.arange(len(D_chunk)), labels[start : start + len(D_chunk)])    # intra_clust_dists are averaged over cluster size outside this function    intra_clust_dists = clust_dists[intra_index]    if issparse(D_chunk):        if D_chunk.format != "csr":            raise TypeError(                "Expected CSR matrix. Please pass sparse matrix in CSR format."            )        for i in range(n_chunk_samples):            indptr = D_chunk.indptr            indices = D_chunk.indices[indptr[i] : indptr[i + 1]]            sample_weights = D_chunk.data[indptr[i] : indptr[i + 1]]            sample_labels = np.take(labels, indices)            cluster_distances[i] += np.bincount(                sample_labels, weights=sample_weights, minlength=len(label_freqs)            )    else:        for i in range(n_chunk_samples):            sample_weights = D_chunk[i]            sample_labels = labels            cluster_distances[i] += np.bincount(                sample_labels, weights=sample_weights, minlength=len(label_freqs)            )    # intra_index selects intra-cluster distances within cluster_distances    end = start + n_chunk_samples    intra_index = (np.arange(n_chunk_samples), labels[start:end])    # intra_cluster_distances are averaged over cluster size outside this function    intra_cluster_distances = cluster_distances[intra_index]     # of the remaining distances we normalise and extract the minimum    clust_dists[intra_index] = np.inf    clust_dists /= label_freqs    inter_clust_dists = clust_dists.min(axis=1)    return intra_clust_dists, inter_clust_dists    cluster_distances[intra_index] = np.inf    cluster_distances /= label_freqs    inter_cluster_distances = cluster_distances.min(axis=1)    return intra_cluster_distances, inter_cluster_distances   def silhouette_samples(X, labels, *, metric="euclidean", **kwds):


Question: Parameters     ----------    X : array-like of shape (n_samples_a, n_samples_a) if metric == \    X : {array-like, sparse matrix} of shape (n_samples_a, n_samples_a) if metric == \             "precomputed" or (n_samples_a, n_features) otherwise        An array of pairwise distances between samples, or a feature array.        An array of pairwise distances between samples, or a feature array. If        a sparse matrix is provided, CSR format should be favoured avoiding        an additional copy.      labels : array-like of shape (n_samples,)         Label values for each sample.


Question: .. [2] `Wikipedia entry on the Silhouette Coefficient        <https://en.wikipedia.org/wiki/Silhouette_(clustering)>`_     """    X, labels = check_X_y(X, labels, accept_sparse=["csc", "csr"])    X, labels = check_X_y(X, labels, accept_sparse=["csr"])      # Check for non-zero diagonal entries in precomputed distance matrix     if metric == "precomputed":


Question: )         if X.dtype.kind == "f":             atol = np.finfo(X.dtype).eps * 100            if np.any(np.abs(np.diagonal(X)) > atol):                raise ValueError(error_msg)        elif np.any(np.diagonal(X) != 0):  # integral dtype            raise ValueError(error_msg)            if np.any(np.abs(X.diagonal()) > atol):                raise error_msg        elif np.any(X.diagonal() != 0):  # integral dtype            raise error_msg      le = LabelEncoder()     labels = le.fit_transform(labels)


Question: trapezoidal rule, which uses linear interpolation and can be too     optimistic. <del>    Note: this implementation is restricted to the binary classification task    or multilabel classification task.</del>     Read more in the :ref:`User Guide <precision_recall_f_measure_metrics>`.      Parameters

Add meanaverageprecision Mean average precision (mAP) is a standard multi-class extension of average precision using OVR: (informationretrieval)#Meanaverage_precision Recently I prefer AP over AUC so I think it would be cool to add this. Maybe is interested? probably knows how to do this ;)


Question: >>> y_scores = np.array([0.1, 0.4, 0.35, 0.8])     >>> average_precision_score(y_true, y_scores)     0.83...<ins>    >>> y_true = np.array([0, 0, 1, 1, 2, 2])    >>> y_scores = np.array([    ...     [0.7, 0.2, 0.1],    ...     [0.4, 0.3, 0.3],    ...     [0.1, 0.8, 0.1],    ...     [0.2, 0.3, 0.5],    ...     [0.4, 0.4, 0.2],    ...     [0.1, 0.2, 0.7],    ... ])    >>> average_precision_score(y_true, y_scores)    0.77...</ins>     """      def _binary_uninterpolated_average_precision(


Question: return -np.sum(np.diff(recall) * np.array(precision)[:-1])      y_type = type_of_target(y_true, input_name="y_true")    if y_type == "multilabel-indicator" and pos_label != 1:        raise ValueError(            "Parameter pos_label is fixed to 1 for "            "multilabel-indicator y_true. Do not set "            "pos_label or set pos_label to 1."        )    elif y_type == "binary":        # Convert to Python primitive type to avoid NumPy type / Python str        # comparison. See https://github.com/numpy/numpy/issues/6784        present_labels = np.unique(y_true).tolist()    # Convert to Python primitive type to avoid NumPy type / Python str    # comparison. See https://github.com/numpy/numpy/issues/6784    present_labels = np.unique(y_true).tolist()    if y_type == "binary":         if len(present_labels) == 2 and pos_label not in present_labels:             raise ValueError(                 f"pos_label={pos_label} is not a valid label. It should be "                 f"one of {present_labels}"             )    elif y_type == "multilabel-indicator" and pos_label != 1:        raise ValueError(            "Parameter pos_label is fixed to 1 for multilabel-indicator y_true. "            "Do not set pos_label or set pos_label to 1."        )    elif y_type == "multiclass":        if pos_label != 1:            raise ValueError(                "Parameter pos_label is fixed to 1 for multiclass y_true. "                "Do not set pos_label or set pos_label to 1."            )        y_true = label_binarize(y_true, classes=present_labels)     average_precision = partial(         _binary_uninterpolated_average_precision, pos_label=pos_label     )


Question: y="no_validation",         reset=True,         validate_separately=False,<ins>        cast_to_ndarray=True,</ins>         **check_params,     ):         """Validate input data and set or check the `n_features_in_` attribute.

Preserving dtypes for DataFrame output by transformers that do not modify the input values It would be nice to optionally preserve the dtypes of the input using pandas output for transformers . Dtypes can contain information relevant for later steps of the analyses. E.g. if I include pd.categorical columns to represent ordinal data and then select features using a sklearn transformer the columns will loose their categorical dtype. This means I loose important information for later analyses steps. This is not only relevant for the categorical dtypes, but could expand to others dtypes (existing, future and custom). Furthermore, this would allow to sequentially use ColumnTransformer while preserving the dtypes (maybe related to ). Currently, this behavior is not given as one can see with this code snippet (minimal example for illustration purposes): Output (using sklearn version '1.2.dev0'): The ouput shows that both the and are converted to in the dataframe output. Maybe one could adjust the to also allow to preserve the dtypes. This would mean one changes the to add: another argument to . If not None the outputted dataframe uses to set the . The of the could be provided to by if the dtypes is set to preserve in the config. One could adjust specific transformers for which this might be relevant. Such a solution would need more work and does not seem to be inline with the simplicity that pandas output provides to the user for every transformer. is also interested in this feature.


Question: `estimator=self` is automatically added to these dicts to generate             more informative error message in case of invalid input data. <ins>        cast_to_ndarray : bool, default=True            Cast `X` and `y` to ndarray with checks in `check_params`. If            `False`, `X` and `y` are unchanged and only `feature_names` and            `n_features_in_` are checked.</ins>         **check_params : kwargs             Parameters passed to :func:`sklearn.utils.check_array` or             :func:`sklearn.utils.check_X_y`. Ignored if validate_separately


Question: if no_val_X and no_val_y:             raise ValueError("Validation should be done on X, y or both.")         elif not no_val_X and no_val_y:            X = check_array(X, input_name="X", **check_params)            if cast_to_ndarray:                X = check_array(X, input_name="X", **check_params)             out = X         elif no_val_X and not no_val_y:            y = _check_y(y, **check_params)            if cast_to_ndarray:                y = _check_y(y, **check_params) if cast_to_ndarray else y             out = y         else:            if validate_separately:            if validate_separately and cast_to_ndarray:                 # We need this because some estimators validate X and y                 # separately, and in general, separately calling check_array()                 # on X and y isn't equivalent to just calling check_X_y()diff --git a/sklearn/feature_selection/_base.py b/sklearn/feature_selection/_base.py-- a/sklearn/feature_selection/_base.py++ b/sklearn/feature_selection/_base.py


Question: from ..cross_decomposition._pls import _PLS from ..utils import (     check_array,    safe_mask,     safe_sqr, ) from ..utils._tags import _safe_tagsfrom ..utils import _safe_indexingfrom ..utils._set_output import _get_output_config from ..utils.validation import _check_feature_names_in, check_is_fitted


Question: X_r : array of shape [n_samples, n_selected_features]             The input samples with only the selected features.         """<ins>        # Preserve X when X is a dataframe and the output is configured to        # be pandas.        output_config_dense = _get_output_config("transform", estimator=self)["dense"]        preserve_X = hasattr(X, "iloc") and output_config_dense == "pandas"</ins>         # note: we use _safe_tags instead of _get_tags because this is a         # public Mixin.         X = self._validate_data(


Question: dtype=None,             accept_sparse="csr",             force_all_finite=not _safe_tags(self, key="allow_nan"),<ins>            cast_to_ndarray=not preserve_X,</ins>             reset=False,         )         return self._transform(X)


Question: " too noisy or the selection test too strict.",                 UserWarning,             )            if hasattr(X, "iloc"):                return X.iloc[:, :0]             return np.empty(0, dtype=X.dtype).reshape((X.shape[0], 0))        if len(mask) != X.shape[1]:            raise ValueError("X has a different shape than during fitting.")        return X[:, safe_mask(X, mask)]        return _safe_indexing(X, mask, axis=1)      def inverse_transform(self, X):         """Reverse the transformation operation.


Question: Which strategy to use to initialize the missing values. Same as the         `strategy` parameter in :class:`~sklearn.impute.SimpleImputer`. <ins>    fill_value : str or numerical value, default=None        When `strategy="constant"`, `fill_value` is used to replace all        occurrences of missing_values. For string or object data types,        `fill_value` must be a string.        If `None`, `fill_value` will be 0 when imputing numerical        data and "missing_value" for strings or object data types.        .. versionadded:: 1.3</ins>     imputation_order : {'ascending', 'descending', 'roman', 'arabic', \             'random'}, default='ascending'         The order in which the features will be imputed. Possible values:

IterativeImputer has no parameter "fillvalue" In the first imputation round of , an initial value needs to be set for the missing values. From its : I have set the initial strategy to . However, I want to define this constant myself. So, as I look at the parameters for I find : When strategy == “constant”, fillvalue is used to replace all occurrences of missingvalues. If left to the default, fillvalue will be 0 when imputing numerical data and “missingvalue” for strings or object data types. Based on this information, one would assume that also has the parameter , but it does not. The parameter needs to be to for when is set to . If this parameter is , please also allow as , for optimal compatibility with decision tree-based estimators. No response No response


Question: "initial_strategy": [             StrOptions({"mean", "median", "most_frequent", "constant"})         ],<ins>        "fill_value": "no_validation",  # any object is valid</ins>         "imputation_order": [             StrOptions({"ascending", "descending", "roman", "arabic", "random"})         ],


Question: tol=1e-3,         n_nearest_features=None,         initial_strategy="mean",<ins>        fill_value=None,</ins>         imputation_order="ascending",         skip_complete=False,         min_value=-np.inf,


Question: self.tol = tol         self.n_nearest_features = n_nearest_features         self.initial_strategy = initial_strategy<ins>        self.fill_value = fill_value</ins>         self.imputation_order = imputation_order         self.skip_complete = skip_complete         self.min_value = min_value


Question: self.initial_imputer_ = SimpleImputer(                 missing_values=self.missing_values,                 strategy=self.initial_strategy,<ins>                fill_value=self.fill_value,</ins>                 keep_empty_features=self.keep_empty_features,             )             X_filled = self.initial_imputer_.fit_transform(X)


Question: The default value changed from `1e-15` to `"auto"` that is            equivalent to `np.finfo(y_pred.dtype).eps`. <ins>        .. deprecated:: 1.3           `eps` is deprecated in 1.3 and will be removed in 1.5.</ins>     normalize : bool, default=True         If true, return the mean loss per sample.         Otherwise, return the sum of the per-sample losses.

BUG logloss renormalizes the predictions renormalizes internally such that it sums to 1. This way, a really bad model, the predictions of which do not sum to 1, gets a better loss then it actually has. Result: Result:


Question: y_pred = check_array(         y_pred, ensure_2d=False, dtype=[np.float64, np.float32, np.float16]     )    eps = np.finfo(y_pred.dtype).eps if eps == "auto" else eps    if eps == "auto":        eps = np.finfo(y_pred.dtype).eps    else:        # TODO: Remove user defined eps in 1.5        warnings.warn(            "Setting the eps parameter is deprecated and will "            "be removed in 1.5. Instead eps will always have"            "a default value of `np.finfo(y_pred.dtype).eps`.",            FutureWarning,        )      check_consistent_length(y_pred, y_true, sample_weight)     lb = LabelBinarizer()


Question: # Renormalize     y_pred_sum = y_pred.sum(axis=1)<ins>    if not np.isclose(y_pred_sum, 1, rtol=1e-15, atol=5 * eps).all():        warnings.warn(            "The y_pred values do not sum to one. Starting from 1.5 this"            "will result in an error.",            UserWarning,        )</ins>     y_pred = y_pred / y_pred_sum[:, np.newaxis]     loss = -xlogy(transformed_labels, y_pred).sum(axis=1)


Question: safe_sqr, ) from ..utils._tags import _safe_tagsfrom ..utils.validation import _check_feature_names_infrom ..utils.validation import _check_feature_names_in, check_is_fitted   class SelectorMixin(TransformerMixin, metaclass=ABCMeta):

Make error message uniform when calling before While working , we found out that we are not consistent with the error type and message when calling before . From Please link the PRs you'll make with this issue so that I can update this list for all of us to know which estimators have been worked on: [x] AdditiveChi2Sampler() [x] Binarizer() [x] MaxAbsScaler() [x] MinMaxScaler() [x] Normalizer() [x] OrdinalEncoder() [x] PowerTransformer() [x] QuantileTransformer() [x] RobustScaler() [x] StackingClassifier() [x] StackingRegressor() [x] StandardScaler() [x] TfidfTransformer() [x] VotingClassifier() [x] VotingRegressor() [x] GaussianRandomProjection() [x] GenericUnivariateSelect() [x] IterativeImputer() [x] RFE() [x] RFECV() [x] SelectFdr() [x] SelectFpr() [x] SelectFromModel() [x] SelectFwe() [x] SelectKBest() [x] SelectPercentile() [x] SequentialFeatureSelector() [x] SparseRandomProjection() [x] VarianceThreshold() [x] KNNImputer() [x] SimpleImputer() [x] SplineTransformer() [x] DictVectorizer() [x] KBinsDiscretizer() [x] MissingIndicator() [x] IsotonicRegression() <details</detailsI assume that the most adequate error should be a asking to fit the estimator. WDYT?


Question: feature_names_out : ndarray of str objects             Transformed feature names.         """        check_is_fitted(self)         input_features = _check_feature_names_in(self, input_features)         return input_features[self.get_support()] diff --git a/sklearn/random_projection.py b/sklearn/random_projection.py-- a/sklearn/random_projection.py++ b/sklearn/random_projection.py


Question: if self.compute_inverse_components:             self.inverse_components_ = self._compute_inverse_components()         return self    @property    def _n_features_out(self):        """Number of transformed output features.        # Required by ClassNamePrefixFeaturesOutMixin.get_feature_names_out.        self._n_features_out = self.n_components         Used by ClassNamePrefixFeaturesOutMixin.get_feature_names_out.        """        return self.n_components        return self      def inverse_transform(self, X):         """Project data back to its original space.


Question: svd_solver="randomized",                 random_state=random_state,             )<ins>            # Always output a numpy array, no matter what is configured globally            pca.set_output(transform="default")</ins>             X_embedded = pca.fit_transform(X).astype(np.float32, copy=False)             # PCA is rescaled so that PC1 has standard deviation 1e-4 which is             # the default value for random initialization. See issue #18018.

sklearn.setconfig(transformoutput="pandas") breaks TSNE embeddings TSNE doesn't work when the I tracked down this bug in the sklearn codebase. The issue is here: What's happening is that returns a Pandas array under API, with the columns being named "pca0" and "pca1". So when is called, we get an IndexError, because you'd have to index with in this situation. Possible fix could be changing line 996 to this: which I am happy to make a PR to do unless somebody has a cleaner way. Cheers! No error is thrown, a 2-dimensional pandas array is returned


Question: batch_size = np.clip(self.batch_size, 1, n_samples)          try:<ins>            self.n_iter_ = 0</ins>             for it in range(self.max_iter):                 if self.shuffle:                     # Only shuffle the sample indices instead of X and y to

With MLPClassifer, when warmstart is True or coeffs are provided, fit doesn’t respect maxiters With MLPClassifer, when warmstart is True or coeffs are provided, fit doesn’t respect maxiters. The reason for this is, when fitting, max iteration check is equality (==) against When warmstart is true or coeffs are provided, initialize is not called; this method resets niter to 0. Based on this implementation, there is doubt as to the meaning of maxiter. Consider, if maxiter is 1 and fit terminates due to reaching maximum iterations, subsequent fittings with warmstart true will never terminate due to reaching maximum iterations. This is bug. An alternate interpretation is maxiter represents the maximum iterations per fit call. In this case, the implementation is also wrong. The later interpretation seems more reasonable. Iteration 1, loss = 0. ConvergenceWarning: Stochastic Optimizer: Maximum iterations reached and the optimization hasn't converged yet. Iteration 2, loss = 0. ConvergenceWarning: Stochastic Optimizer: Maximum iterations reached and the optimization hasn't converged yet. Iteration 3, loss = 0. ConvergenceWarning: Stochastic Optimizer: Maximum iterations reached and the optimization hasn't converged yet. Iteration 1, loss = 0. ConvergenceWarning: Stochastic Optimizer: Maximum iterations reached and the optimization hasn't converged yet. Iteration 2, loss = 0. Iteration 3, loss = 0. Windows-7-6.1.7601-SP1 Python 3.6.0 (v3.6.0:, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] NumPy 1.12.0 SciPy 0.18.1 Scikit-Learn 0.18.1


Question: self._build_f(X, y)         return self     def transform(self, T):        """Transform new data by linear interpolation.        Parameters        ----------        T : array-like of shape (n_samples,) or (n_samples, 1)            Data to transform.    def _transform(self, T):        """`_transform` is called by both `transform` and `predict` methods.             .. versionchanged:: 0.24               Also accepts 2d array with 1 feature.        Since `transform` is wrapped to output arrays of specific types (e.g.        NumPy arrays, pandas DataFrame), we cannot make `predict` call `transform`        directly.         Returns        -------        y_pred : ndarray of shape (n_samples,)            The transformed data.        The above behaviour could be changed in the future, if we decide to output        other type of arrays when calling `predict`.         """         if hasattr(self, "X_thresholds_"):             dtype = self.X_thresholds_.dtype         else:

CalibratedClassifierCV doesn't work with CalibratedClassifierCV with isotonic regression doesn't work when we previously set . The IsotonicRegression seems to return a dataframe, which is a problem for in where it tries to put the dataframe in a numpy array row . It should not crash.


Question: return res <ins>    def transform(self, T):        """Transform new data by linear interpolation.        Parameters        ----------        T : array-like of shape (n_samples,) or (n_samples, 1)            Data to transform.            .. versionchanged:: 0.24               Also accepts 2d array with 1 feature.        Returns        -------        y_pred : ndarray of shape (n_samples,)            The transformed data.        """        return self._transform(T)</ins>     def predict(self, T):         """Predict new data by linear interpolation.


Question: y_pred : ndarray of shape (n_samples,)             Transformed data.         """        return self.transform(T)        return self._transform(T)      # We implement get_feature_names_out here instead of using     # `ClassNamePrefixFeaturesOutMixin`` because `input_features` are ignored.


Question: transformer_names = [                     t[0] for t in self._iter(fitted=True, replace_strings=True)                 ]                feature_names_outs = [X.columns for X in Xs]                # Selection of columns might be empty.                # Hence feature names are filtered for non-emptiness.                feature_names_outs = [X.columns for X in Xs if X.shape[1] != 0]                 names_out = self._add_prefix_for_feature_names_out(                     list(zip(transformer_names, feature_names_outs))                 )

ColumnTransformer with pandas output can't handle transformers with no features Hi, ColumnTransformer doesn't deal well with transformers that apply to 0 features (categoricalfeatures in the example below) when using "pandas" as output. It seems steps with 0 features are not fitted, hence don't appear in ( l.856) and hence break the input to the function (l.859). Here is some code to reproduce the error. If you remove .set_output(transform="pandas") on the line before last, all works fine. If you remove the ("categorical", ...) step, it works fine too. The step with no features should be ignored. Here is the error message:


Question: return max_samples      if isinstance(max_samples, Real):        return round(n_samples * max_samples)        return max(round(n_samples * max_samples), 1)   def _generate_sample_indices(random_state, n_samples, n_samples_bootstrap):

RandomForestClassifier classweight/maxsamples interaction can lead to ungraceful and nondescriptive failure The acceptable values for are . One possible option for is . However, for values of near zero and , the model fails with an unhelpful error related to having an empty array as an indexer. This is only likely to come up in a grid search, as it seems unlikely that someone would deliberately force a subsample of zero items. However, it might be useful to have a minimum of one sample, or it might be useful to fail gracefully with a more descriptive error. EITHER: No error is thrown OR


Question: - If None (default), then draw `X.shape[0]` samples.         - If int, then draw `max_samples` samples.        - If float, then draw `max_samples * X.shape[0]` samples. Thus,        - If float, then draw `max(round(n_samples * max_samples), 1)` samples. Thus,           `max_samples` should be in the interval `(0.0, 1.0]`.          .. versionadded:: 0.22


Question: - If None (default), then draw `X.shape[0]` samples.         - If int, then draw `max_samples` samples.        - If float, then draw `max_samples * X.shape[0]` samples. Thus,        - If float, then draw `max(round(n_samples * max_samples), 1)` samples. Thus,           `max_samples` should be in the interval `(0.0, 1.0]`.          .. versionadded:: 0.22


Question: if hasattr(y, "__array__") or isinstance(y, Sequence) or is_array_api:         # DeprecationWarning will be replaced by ValueError, see NEP 34         # https://numpy.org/neps/nep-0034-infer-dtype-is-object.html        check_y_kwargs = dict(            accept_sparse=True,            allow_nd=True,            force_all_finite=False,            ensure_2d=False,            ensure_min_samples=0,            ensure_min_features=0,        )         with warnings.catch_warnings():             warnings.simplefilter("error", np.VisibleDeprecationWarning)             try:                y = xp.asarray(y)            except (np.VisibleDeprecationWarning, ValueError):                y = check_array(y, dtype=None, **check_y_kwargs)            except (np.VisibleDeprecationWarning, ValueError) as e:                if str(e).startswith("Complex data not supported"):                    raise                 # dtype=object should be provided explicitly for ragged arrays,                 # see NEP 34                y = xp.asarray(y, dtype=object)                y = check_array(y, dtype=object, **check_y_kwargs)      if not (hasattr(y, "shape") and y.ndim == 2 and y.shape[1] > 1):         return False

Support nullable pandas dtypes in I would like to be able to pass the nullable pandas dtypes ("Int64", "Float64", "boolean") into sklearn's function. Because the dtypes become dtype when converted to numpy arrays we get : Repro with sklearn 1.2.1 We should get the same behavior as when , , and dtypes are used, which is no error: Our current workaround is to convert the data to numpy arrays with the corresponding dtype that works prior to passing it into . No response_


Question: # https://numpy.org/neps/nep-0034-infer-dtype-is-object.html     # We therefore catch both deprecation (NumPy < 1.24) warning and     # value error (NumPy >= 1.24).    check_y_kwargs = dict(        accept_sparse=True,        allow_nd=True,        force_all_finite=False,        ensure_2d=False,        ensure_min_samples=0,        ensure_min_features=0,    )     with warnings.catch_warnings():         warnings.simplefilter("error", np.VisibleDeprecationWarning)         if not issparse(y):             try:                y = xp.asarray(y)            except (np.VisibleDeprecationWarning, ValueError):                y = check_array(y, dtype=None, **check_y_kwargs)            except (np.VisibleDeprecationWarning, ValueError) as e:                if str(e).startswith("Complex data not supported"):                    raise                 # dtype=object should be provided explicitly for ragged arrays,                 # see NEP 34                y = xp.asarray(y, dtype=object)                y = check_array(y, dtype=object, **check_y_kwargs)      # The old sequence of sequences format     try:


Question: if y_true.min() < 0:         # TODO(1.4): Replace warning w/ ValueError         warnings.warn(            "ndcg_score should not be used on negative y_true values. ndcg_score will"            " raise a ValueError on negative y_true values starting from version 1.4.",            "ndcg_score should not be used on negative y_true values. ndcg_score"            " will raise a ValueError on negative y_true values starting from"            " version 1.4.",             FutureWarning,         )    if y_true.ndim > 1 and y_true.shape[1] <= 1:        raise ValueError(            "Computing NDCG is only meaningful when there is more than 1 document. "            f"Got {y_true.shape[1]} instead."        )     _check_dcg_target_type(y_true)     gain = _ndcg_sample_scores(y_true, y_score, k=k, ignore_ties=ignore_ties)     return np.average(gain, weights=sample_weight)

NDCG score doesn't work with binary relevance and a list of 1 element See this code example: It works correctly when the number of elements is bigger than 1: score and Computing does not make sense for single predictions. Throw an error if is a list of length 1 for NDCG and DCG. Test that this throws the appropriate error by running: <!-- Please be aware that we are a loose team of volunteers so patience is necessary; assistance handling other issues is very welcome. We value all user contributions, no matter how minor they are. If we are slow to review, either the pull request needs some benchmarking, tinkering, convincing, etc. or more likely the reviewers are simply busy. In either case, we ask for your understanding during the review process. For more information, see our FAQ on this topic: http://scikit- Thanks for contributing! --


Question: )          # early_stopping in partial_fit doesn't make sense        early_stopping = self.early_stopping and not incremental        if self.early_stopping and incremental:            raise ValueError("partial_fit does not support early_stopping=True")        early_stopping = self.early_stopping         if early_stopping:             # don't stratify in multilabel classification             should_stratify = is_classifier(self) and self.n_outputs_ == 1

MLPRegressor.partialfit produces an error when earlystopping is True WIth , when using , works fine, but partial fit produces the following error: I think this is related to this change: If early stopping is not supported for partial fit, it should handle this gracefully. If this is a bug - it should be fixed.


Question: if self.extra:             msg += "; %s" % self.extra         # FIXME: we should probably reset __new__ for full generality        init = cls.__init__        new = cls.__new__         def wrapped(*args, **kwargs):        def wrapped(cls, *args, **kwargs):             warnings.warn(msg, category=FutureWarning)            return init(*args, **kwargs)            if new is object.__new__:                return object.__new__(cls)            return new(cls, *args, **kwargs)         cls.__init__ = wrapped        cls.__new__ = wrapped         wrapped.__name__ = "__init__"        wrapped.deprecated_original = init        wrapped.__name__ = "__new__"        wrapped.deprecated_original = new          return cls

FutureWarning is not issued for deprecated class FutureWarning is not issued when using as a baseclass but its is not called in the subclass, here: As the comment suggest in your decorator, overriding ` in the class decorator indeed solves this issue. I'm happy to open a PR with the fix. Also, relatedly, I wonder whether you would be interested in using a generic deprecation package instead. Basically we have the same functionality in astropy (I feel it's actually has more features e.g. this works there out of the box, it helps with arg renames/removals, etc.), there is also a deprecated decorator in matplotlib, and also a very basic one in numpy. I feel that having one for the wider ecosystem would be beneficial instead of the current system where we all roll our own. At the numfocus summit I recall some interest from the mpl side, so I'm happy to get the ball rolling in this quoter if it's a thumb up from multiple projects. Darwin-17.7.0-x8664-i386-64bit Python 3.7.5 (default, Nov 1 2019, 02:16:38) [Clang 10.0.0 (clang-1000.11.45.5)] NumPy 1.19.0.dev0+ SciPy 1.4.1 Scikit-Learn 0.23.dev0 Quick fix for class deprecation decorator This is a quick and dirty fix for my use case, but looking at the astropy decorator I suspect there may be some corner cases that still doesn't work.


Question: "max_depth": [Interval(Integral, 1, None, closed="left"), None],         "min_samples_split": [             Interval(Integral, 2, None, closed="left"),            Interval(Real, 0.0, 1.0, closed="right"),            Interval("real_not_int", 0.0, 1.0, closed="right"),         ],         "min_samples_leaf": [             Interval(Integral, 1, None, closed="left"),            Interval(Real, 0.0, 1.0, closed="neither"),            Interval("real_not_int", 0.0, 1.0, closed="neither"),         ],         "min_weight_fraction_leaf": [Interval(Real, 0.0, 0.5, closed="both")],         "max_features": [             Interval(Integral, 1, None, closed="left"),            Interval(Real, 0.0, 1.0, closed="right"),            Interval("real_not_int", 0.0, 1.0, closed="right"),             StrOptions({"auto", "sqrt", "log2"}, deprecated={"auto"}),             None,         ],diff --git a/sklearn/utils/_param_validation.py b/sklearn/utils/_param_validation.py-- a/sklearn/utils/_param_validation.py++ b/sklearn/utils/_param_validation.py

Setting minsamplessplit=1 in DecisionTreeClassifier does not raise exception If is set to 1, an exception should be raised according to the paramter's constraints: However, accepts without complaining. With scikit-survival 1.0, this raises an exception as expected: I suspect that this has to do with the Intervals of the constraints overlapping. satisfies the constraint, whereas the constraint should have precedence. No exception is raised.


Question: Parameters     ----------    type : {numbers.Integral, numbers.Real}    type : {numbers.Integral, numbers.Real, "real_not_int"}         The set of numbers in which to set the interval.         If "real_not_int", only reals that don't have the integer type        are allowed. For example 1.0 is allowed but 1 is not.     left : float or int or None         The left bound of the interval. None means left bound is -∞.


Question: `[0, +∞) U {+∞}`.     """ <del>    @validate_params(        {            "type": [type],            "left": [Integral, Real, None],            "right": [Integral, Real, None],            "closed": [StrOptions({"left", "right", "both", "neither"})],        }    )</del>     def __init__(self, type, left, right, *, closed):         super().__init__()         self.type = type


Question: self._check_params()      def _check_params(self):<ins>        if self.type not in (Integral, Real, "real_not_int"):            raise ValueError(                "type must be either numbers.Integral, numbers.Real or 'real_not_int'."                f" Got {self.type} instead."            )        if self.closed not in ("left", "right", "both", "neither"):            raise ValueError(                "closed must be either 'left', 'right', 'both' or 'neither'. "                f"Got {self.closed} instead."            )</ins>         if self.type is Integral:             suffix = "for an interval over the integers."             if self.left is not None and not isinstance(self.left, Integral):


Question: raise ValueError(                     f"right can't be None when closed == {self.closed} {suffix}"                 )<ins>        else:            if self.left is not None and not isinstance(self.left, Real):                raise TypeError("Expecting left to be a real number.")            if self.right is not None and not isinstance(self.right, Real):                raise TypeError("Expecting right to be a real number.")</ins>          if self.right is not None and self.left is not None and self.right <= self.left:             raise ValueError(


Question: return False         return True     def _has_valid_type(self, val):        if self.type == "real_not_int":            return isinstance(val, Real) and not isinstance(val, Integral)        return isinstance(val, self.type)     def is_satisfied_by(self, val):        if not isinstance(val, self.type):        if not self._has_valid_type(val):             return False          return val in self


Question: `range(n_features)`.      index : array-like, default=None        Index for data.        Index for data. `index` is ignored if `data_to_wrap` is already a DataFrame.      Returns     -------

FeatureUnion not working when aggregating data and pandas transform output selected I would like to use transform output and use a custom transformer in a feature union which aggregates data. When I'm using this combination I got an error. When I use default output it works fine. No error is thrown when using transform output.


Question: if isinstance(data_to_wrap, pd.DataFrame):         if columns is not None:             data_to_wrap.columns = columns<del>        if index is not None:            data_to_wrap.index = index</del>         return data_to_wrap      return pd.DataFrame(data_to_wrap, index=index, columns=columns)


Question: raise ValueError("'grid_resolution' must be strictly greater than 1.")      values = []    # TODO: we should handle missing values (i.e. `np.nan`) specifically and store them    # in a different Bunch attribute.     for feature, is_cat in enumerate(is_categorical):        uniques = np.unique(_safe_indexing(X, feature, axis=1))        try:            uniques = np.unique(_safe_indexing(X, feature, axis=1))        except TypeError as exc:            # `np.unique` will fail in the presence of `np.nan` and `str` categories            # due to sorting. Temporary, we reraise an error explaining the problem.            raise ValueError(                f"The column #{feature} contains mixed data types. Finding unique "                "categories fail due to sorting. It usually means that the column "                "contains `np.nan` values together with `str` categories. Such use "                "case is not yet supported in scikit-learn."            ) from exc         if is_cat or uniques.shape[0] < grid_resolution:             # Use the unique values either because:             # - feature has low resolution use unique values

FIX ignore nan values in partial dependence computation This PR implements the default behaviour suggested in that is ignoring values in both numerical and categorical features. Up to now, there is a bug since the computation of the percentile is impacted by the values for numerical features. In addition, introducing in the grid will potentially introduce a bias in the partial dependence computation depending on how missing values are handled in the model. Therefore, it is safe to remove them. To be consistent, then it is also safe to not include it as a category in the categorical features. In the future, we can think of adding an option to define the expected behaviour. I expect this PR to fail because we use instead of that does not use the same interpolation to compute the quantiles.


Question: if sample_weight is not None:             sample_weight = _check_sample_weight(sample_weight, X) <del>        for sample_aligned_params in fit_params.values():            check_consistent_length(y, sample_aligned_params)</del>         # TODO(1.4): Remove when base_estimator is removed         if self.base_estimator != "deprecated":             if self.estimator is not None:

CalibratedClassifierCV fails on lgbm fitparams Hi, I'm trying to use CalibratedClassifierCV to calibrate the probabilities from a LGBM model. The issue is that when I try CalibratedClassifierCV with evalset, I get an error ValueError: Found input variables with inconsistent numbers of samples: [, 1] which is caused by checkconsistentlength function in The input to eval set is [Xvalid,Yvalid] where both Xvalid,Yvalid are arrays with different shape. Since this format is a requirement for LGBM eval set , I am not sure how will I make the checkconsistentlength pass in my scenario. Full code is given below: = (, 152) = (,) = (, 152) = (,)


Question: self.offset_ = -0.5             return self         # else, define offset_ wrt contamination parameter        self.offset_ = np.percentile(self.score_samples(X), 100.0 * self.contamination)        # Else, define offset_ wrt contamination parameter        # To avoid performing input validation a second time we call        # _score_samples rather than score_samples        self.offset_ = np.percentile(self._score_samples(X), 100.0 * self.contamination)          return self

X does not have valid feature names, but IsolationForest was fitted with feature names If you fit an using a it generates a warning This only seems to occur if you supply a non-default value (i.e. not "auto") for the parameter. This warning is unexpected as a) X does have valid feature names and b) it is being raised by the method but in general is supposed to indicate that predict has been called with ie. an ndarray but the model was fitted using a dataframe. The reason is most likely when you pass contamination != "auto" the estimator essentially calls predict on the training data in order to determine the parameters: Does not raise "X does not have valid feature names, but IsolationForest was fitted with feature names" raises "X does not have valid feature names, but IsolationForest was fitted with feature names"


Question: The anomaly score of the input samples.             The lower, the more abnormal.         """        # code structure from ForestClassifier/predict_proba        check_is_fitted(self)         # Check data         X = self._validate_data(X, accept_sparse="csr", dtype=np.float32, reset=False)         # Take the opposite of the scores as bigger is better (here less        # abnormal)        return self._score_samples(X)    def _score_samples(self, X):        """Private version of score_samples without input validation.        Input validation would remove feature names, so we disable it.        """        # Code structure from ForestClassifier/predict_proba        check_is_fitted(self)        # Take the opposite of the scores as bigger is better (here less abnormal)         return -self._compute_chunked_score_samples(X)      def _compute_chunked_score_samples(self, X):


Question: import warnings  from ._base import SelectorMixinfrom ..base import BaseEstimator, MetaEstimatorMixin, clonefrom ..base import BaseEstimator, MetaEstimatorMixin, clone, is_classifier from ..utils._param_validation import HasMethods, Hidden, Interval, StrOptions from ..utils._param_validation import RealNotInt from ..utils._tags import _safe_tags from ..utils.validation import check_is_fittedfrom ..model_selection import cross_val_scorefrom ..model_selection import cross_val_score, check_cv from ..metrics import get_scorer_names

Unable to pass splits to SequentialFeatureSelector This runs fine with e.g. , but according to the documentation, it should also be able to take an iterable of splits. However, passing splits from the cross validator fails Im fairly certain I have done similar things in the past to other classes in scikit-learn requiring a parameter. If somebody could confirm wether this is a bug, or I'm doing something wrong, that would great. Sorry if this is unneeded noise in the feed. Expected to run without errors


Question: if self.tol is not None and self.tol < 0 and self.direction == "forward":             raise ValueError("tol must be positive when doing forward selection") <ins>        cv = check_cv(self.cv, y, classifier=is_classifier(self.estimator))</ins>         cloned_estimator = clone(self.estimator)          # the current mask corresponds to the set of features:


Question: is_auto_select = self.tol is not None and self.n_features_to_select == "auto"         for _ in range(n_iterations):             new_feature_idx, new_score = self._get_best_new_feature_score(                cloned_estimator, X, y, current_mask                cloned_estimator, X, y, cv, current_mask             )             if is_auto_select and ((new_score - old_score) < self.tol):                 break


Question: return self     def _get_best_new_feature_score(self, estimator, X, y, current_mask):    def _get_best_new_feature_score(self, estimator, X, y, cv, current_mask):         # Return the best new feature and its score to add to the current_mask,         # i.e. return the best new feature and its score to add (resp. remove)         # when doing forward selection (resp. backward selection).


Question: estimator,                 X_new,                 y,                cv=self.cv,                cv=cv,                 scoring=self.scoring,                 n_jobs=self.n_jobs,             ).mean()


Question: Increasing true positive rates such that element `i` is the true         positive rate of predictions with score >= `thresholds[i]`.     thresholds : ndarray of shape = (n_thresholds,)    thresholds : ndarray of shape (n_thresholds,)         Decreasing thresholds on the decision function used to compute         fpr and tpr. `thresholds[0]` represents no instances being predicted        and is arbitrarily set to `max(y_score) + 1`.        and is arbitrarily set to `np.inf`.      See Also     --------

Thresholds can exceed 1 in while providing probability estimate While working on , I found out that something was odd with that returns a threshold greater than 1. A non-regression test (that could be part of ) could be as follow: The reason is due to the following: Basically, this is to add a point for and . However, the rule does not make sense in the case is a probability estimate. I am not sure what would be the best fix here. A potential workaround would be to check in which case we should clip to not be above 1.


Question: are reversed upon returning them to ensure they correspond to both ``fpr``     and ``tpr``, which are sorted in reversed order during their calculation. <ins>    An arbritrary threshold is added for the case `tpr=0` and `fpr=0` to    ensure that the curve starts at `(0, 0)`. This threshold corresponds to the    `np.inf`.</ins>     References     ----------     .. [1] `Wikipedia entry for the Receiver operating characteristic


Question: >>> tpr     array([0. , 0.5, 0.5, 1. , 1. ])     >>> thresholds    array([1.8 , 0.8 , 0.4 , 0.35, 0.1 ])    array([ inf, 0.8 , 0.4 , 0.35, 0.1 ])     """     fps, tps, thresholds = _binary_clf_curve(         y_true, y_score, pos_label=pos_label, sample_weight=sample_weight


Question: # to make sure that the curve starts at (0, 0)     tps = np.r_[0, tps]     fps = np.r_[0, fps]    thresholds = np.r_[thresholds[0] + 1, thresholds]    # get dtype of `y_score` even if it is an array-like    thresholds = np.r_[np.inf, thresholds]      if fps[-1] <= 0:         warnings.warn(


Question: if self.estimator is not None:             self.estimator_ = self.estimator        elif self.base_estimator not in [None, "deprecated"]:        elif self.base_estimator != "deprecated":             warnings.warn(                 (                     "`base_estimator` was renamed to `estimator` in version 1.2 and "

AdaBoost: deprecation of "baseestimator" does not handle "baseestimator=None" setting properly Scikit-learn 1.2 deprecated 's in favour of (see ). Because there are also validators in place, old code that explicitly defined stopped working. A solution that fixes the deprecation is to add a possible to a list allowed values in ; I will do that in a PR. No error is thrown.


Question: ),                 FutureWarning,             )            self.estimator_ = self.base_estimator            if self.base_estimator is not None:                self.estimator_ = self.base_estimator            else:                self.estimator_ = default         else:             self.estimator_ = default diff --git a/sklearn/ensemble/_weight_boosting.py b/sklearn/ensemble/_weight_boosting.py-- a/sklearn/ensemble/_weight_boosting.py++ b/sklearn/ensemble/_weight_boosting.py


Question: "n_estimators": [Interval(Integral, 1, None, closed="left")],         "learning_rate": [Interval(Real, 0, None, closed="neither")],         "random_state": ["random_state"],        "base_estimator": [HasMethods(["fit", "predict"]), StrOptions({"deprecated"})],        "base_estimator": [            HasMethods(["fit", "predict"]),            StrOptions({"deprecated"}),            None,        ],     }      @abstractmethod


Question: import numpy as np from ..utils.validation import check_is_fittedfrom ..utils.validation import check_is_fitted, check_array from ..utils._param_validation import Interval, validate_params, StrOptions  from ..base import is_classifier

failing when featurenames supplied folks, I'm not sure why this works for but not for Can anyone help?


Question: The maximum depth of the representation. If None, the tree is fully         generated.     feature_names : list of str, default=None        Names of each of the features.    feature_names : array-like of shape (n_features,), default=None        An array containing the feature names.         If None, generic names will be used ("x[0]", "x[1]", ...).     class_names : list of str or bool, default=None    class_names : array-like of shape (n_classes,) or bool, default=None         Names of each of the target classes in ascending numerical order.         Only relevant for classification and not supported for multi-output.         If ``True``, shows a symbolic representation of the class name.


Question: >>> tree.export_graphviz(clf)     'digraph Tree {...     """<ins>    if feature_names is not None:        feature_names = check_array(            feature_names, ensure_2d=False, dtype=None, ensure_min_samples=0        )    if class_names is not None and not isinstance(class_names, bool):        class_names = check_array(            class_names, ensure_2d=False, dtype=None, ensure_min_samples=0        )</ins>      check_is_fitted(decision_tree)     own_file = False


Question: @validate_params(     {         "decision_tree": [DecisionTreeClassifier, DecisionTreeRegressor],        "feature_names": [list, None],        "class_names": [list, None],        "feature_names": ["array-like", None],        "class_names": ["array-like", None],         "max_depth": [Interval(Integral, 0, None, closed="left"), None],         "spacing": [Interval(Integral, 1, None, closed="left"), None],         "decimals": [Interval(Integral, 0, None, closed="left"), None],


Question: It can be an instance of         DecisionTreeClassifier or DecisionTreeRegressor.     feature_names : list of str, default=None        A list of length n_features containing the feature names.    feature_names : array-like of shape (n_features,), default=None        An array containing the feature names.         If None generic names will be used ("feature_0", "feature_1", ...).     class_names : list or None, default=None    class_names : array-like of shape (n_classes,), default=None         Names of each of the target classes in ascending numerical order.         Only relevant for classification and not supported for multi-output.          - if `None`, the class names are delegated to `decision_tree.classes_`;        - if a list, then `class_names` will be used as class names instead          of `decision_tree.classes_`. The length of `class_names` must match        - otherwise, `class_names` will be used as class names instead of          `decision_tree.classes_`. The length of `class_names` must match           the length of `decision_tree.classes_`.          .. versionadded:: 1.3


Question: |   |--- petal width (cm) >  1.75     |   |   |--- class: 2     """<ins>    if feature_names is not None:        feature_names = check_array(            feature_names, ensure_2d=False, dtype=None, ensure_min_samples=0        )    if class_names is not None:        class_names = check_array(            class_names, ensure_2d=False, dtype=None, ensure_min_samples=0        )</ins>     check_is_fitted(decision_tree)     tree_ = decision_tree.tree_     if is_classifier(decision_tree):


Question: class_names = decision_tree.classes_         elif len(class_names) != len(decision_tree.classes_):             raise ValueError(                "When `class_names` is a list, it should contain as"                "When `class_names` is an array, it should contain as"                 " many items as `decision_tree.classes_`. Got"                 f" {len(class_names)} while the tree was fitted with"                 f" {len(decision_tree.classes_)} classes."


Question: else:         value_fmt = "{}{} value: {}\n"     if feature_names:    if feature_names is not None:         feature_names_ = [             feature_names[i] if i != _tree.TREE_UNDEFINED else None             for i in tree_.feature


Question: # Collect newly grown trees             self.estimators_.extend(trees)         if self.oob_score:        if self.oob_score and (            n_more_estimators > 0 or not hasattr(self, "oob_score_")        ):             y_type = type_of_target(y)             if y_type in ("multiclass-multioutput", "unknown"):                 # FIXME: we could consider to support multiclass-multioutput if

Incorrect documentation for behavior on BaseForest-derived classes The documentation states: This is also true for all classes that derive from , such as and . However, the does not reflect this behavior. When , it does not fit a new forest and instead just recomputes the OOB score if applicable. There are two potential fixes: the documentation to state: the actual behavior of this method to fit a new forest in the case where to reflect the existing documentation.


Question: Estimator instance.         """         super().set_output(transform=transform)<ins></ins>         transformers = (             trans             for _, trans, _ in chain(

ignores the if it's an estimator When using on a , it sets the output to its sub-transformers but it ignores the transformer defined in . This issue causes the following to fail when gathering the results: Thus not gathering the final result correctly.


Question: for trans in transformers:             _safe_set_output(trans, transform=transform) <ins>        if self.remainder not in {"passthrough", "drop"}:            _safe_set_output(self.remainder, transform=transform)</ins>         return self      def get_params(self, deep=True):


Question: We here use scipy builtins which uses the brent optimizer.         """        mask = np.isnan(x)        if np.all(mask):            raise ValueError("Column must not be all nan.")         # the computation of lambda is influenced by NaNs so we need to         # get rid of them        _, lmbda = stats.boxcox(x[~np.isnan(x)], lmbda=None)        _, lmbda = stats.boxcox(x[~mask], lmbda=None)          return lmbda

PowerTransformer fails with unhelpful stack trace with all-nan feature and method='box-cox' throws a difficult-to-debug error if x contains an all-nan column. Either no error is thrown and the all-nan column is preserved, or a descriptive error is thrown indicating that there is an unfittable column


Question: .. note::            The fast ``method='recursion'`` option is only available for           ``kind='average'``. Plotting individual dependencies requires using           the slower ``method='brute'`` option.           `kind='average'` and `sample_weights=None`. Computing individual           dependencies and doing weighted averages requires using the slower           `method='brute'`.          .. versionadded:: 0.24            Add `kind` parameter with `'average'`, `'individual'`, and `'both'`

partialdependence should respect sample weights Currently, the inspect.partialdependence funtions calculate arithmetic averages over predictions. For models fitted with sample weights, this is between suboptimal and wrong. Add new argument "sampleweight = None". If vector of right length, replace arithmetic average of predictions by weighted averages. Note that this does not affect the calculation of ICE curves, just the aggregate. No response No response_


Question: X,         features,         *,<ins>        sample_weight=None,</ins>         categorical_features=None,         feature_names=None,         target=None,


Question: with `kind='average'`). Each tuple must be of size 2.             If any entry is a string, then it must be in ``feature_names``. <ins>        sample_weight : array-like of shape (n_samples,), default=None            Sample weights are used to calculate weighted means when averaging the            model output. If `None`, then samples are equally weighted. If            `sample_weight` is not `None`, then `method` will be set to `'brute'`.            Note that `sample_weight` is ignored for `kind='individual'`.            .. versionadded:: 1.3</ins>         categorical_features : array-like of shape (n_features,) or shape \                 (n_categorical_features,), dtype={bool, int, str}, default=None             Indicates the categorical features.


Question: computationally intensive.              - `'auto'`: the `'recursion'` is used for estimators that support it,              and `'brute'` is used otherwise.              and `'brute'` is used otherwise. If `sample_weight` is not `None`,              then `'brute'` is used regardless of the estimator.              Please see :ref:`this note <pdp_method_differences>` for             differences between the `'brute'` and `'recursion'` method.


Question: - ``kind='average'`` results in the traditional PD plot;             - ``kind='individual'`` results in the ICE plot.            Note that the fast ``method='recursion'`` option is only available for           ``kind='average'``. Plotting individual dependencies requires using the           slower ``method='brute'`` option.           Note that the fast `method='recursion'` option is only available for           `kind='average'` and `sample_weights=None`. Computing individual           dependencies and doing weighted averages requires using the slower           `method='brute'`.          centered : bool, default=False             If `True`, the ICE and PD lines will start at the origin of the


Question: estimator,                 X,                 fxs,<ins>                sample_weight=sample_weight,</ins>                 feature_names=feature_names,                 categorical_features=categorical_features,                 response_method=response_method,


Question: sample_weight=sample_weight)  def roc_auc_score(y_true, y_score, average="macro", sample_weight=None):def roc_auc_score(y_true, y_score, average="macro", sample_weight=None,                  max_fpr=None):     """Compute Area Under the Receiver Operating Characteristic Curve (ROC AUC)     from prediction scores.

partial AUC I suggest adding partial AUC to the metrics. this would compute the area under the curve up to a specified FPR (in the case of the ROC curve). this measure is important for comparing classifiers in cases where FPR is much more important than TPR. The partial AUC should also allow applying the McClish correction. see here: http://cran.r-


Question: sample_weight : array-like of shape = [n_samples], optional         Sample weights. <ins>    max_fpr : float > 0 and <= 1, optional        If not ``None``, the standardized partial AUC [3]_ over the range        [0, max_fpr] is returned.</ins>     Returns     -------     auc : float


Question: .. [2] Fawcett T. An introduction to ROC analysis[J]. Pattern Recognition            Letters, 2006, 27(8):861-874. <ins>    .. [3] `Analyzing a portion of the ROC curve. McClish, 1989            <http://www.ncbi.nlm.nih.gov/pubmed/2668680>`_</ins>     See also     --------     average_precision_score : Area under the precision-recall curve


Question: fpr, tpr, tresholds = roc_curve(y_true, y_score,                                         sample_weight=sample_weight)        return auc(fpr, tpr)        if max_fpr is None or max_fpr == 1:            return auc(fpr, tpr)        if max_fpr <= 0 or max_fpr > 1:            raise ValueError("Expected max_frp in range ]0, 1], got: %r"                             % max_fpr)        # Add a single point at max_fpr by linear interpolation        stop = np.searchsorted(fpr, max_fpr, 'right')        x_interp = [fpr[stop - 1], fpr[stop]]        y_interp = [tpr[stop - 1], tpr[stop]]        tpr = np.append(tpr[:stop], np.interp(max_fpr, x_interp, y_interp))        fpr = np.append(fpr[:stop], max_fpr)        partial_auc = auc(fpr, tpr)        # McClish correction: standardize result to be 0.5 if non-discriminant        # and 1 if maximal        min_area = 0.5 * max_fpr**2        max_area = max_fpr        return 0.5 * (1 + (partial_auc - min_area) / (max_area - min_area))      y_type = type_of_target(y_true)     if y_type == "binary":


Question: class TestCase(unittest.TestCase):    longMessage = False    longMessage = True     failureException = AssertionError      def _formatMessage(self, msg, standardMsg):diff --git a/sklearn/utils/estimator_checks.py b/sklearn/utils/estimator_checks.py-- a/sklearn/utils/estimator_checks.py++ b/sklearn/utils/estimator_checks.py

Stronger common tests for setting init params? / checkestimator In a solution was proposed that did something like The common tests let this pass, though that should wreck havoc on and . I haven't looked into it but I think the tests should fail on this.


Question: yield check_fit2d_1feature     yield check_fit1d     yield check_get_params_invariance<ins>    yield check_set_params</ins>     yield check_dict_unchanged     yield check_dont_overwrite_parameters


Question: shallow_params.items()))  <ins>@ignore_warnings(category=(DeprecationWarning, FutureWarning))def check_set_params(name, estimator_orig):    # Check that get_params() returns the same thing    # before and after set_params() with some fuzz    estimator = clone(estimator_orig)    orig_params = estimator.get_params(deep=False)    msg = ("get_params result does not match what was passed to set_params")    estimator.set_params(**orig_params)    curr_params = estimator.get_params(deep=False)    assert_equal(set(orig_params.keys()), set(curr_params.keys()), msg)    for k, v in curr_params.items():        assert orig_params[k] is v, msg    # some fuzz values    test_values = [-np.inf, np.inf, None]    test_params = deepcopy(orig_params)    for param_name in orig_params.keys():        default_value = orig_params[param_name]        for value in test_values:            test_params[param_name] = value            try:                estimator.set_params(**test_params)            except (TypeError, ValueError) as e:                e_type = e.__class__.__name__                # Exception occurred, possibly parameter validation                warnings.warn("{} occurred during set_params. "                              "It is recommended to delay parameter "                              "validation until fit.".format(e_type))                change_warning_msg = "Estimator's parameters changed after " \                                     "set_params raised {}".format(e_type)                params_before_exception = curr_params                curr_params = estimator.get_params(deep=False)                try:                    assert_equal(set(params_before_exception.keys()),                                 set(curr_params.keys()))                    for k, v in curr_params.items():                        assert params_before_exception[k] is v                except AssertionError:                    warnings.warn(change_warning_msg)            else:                curr_params = estimator.get_params(deep=False)                assert_equal(set(test_params.keys()),                             set(curr_params.keys()),                             msg)                for k, v in curr_params.items():                    assert test_params[k] is v, msg        test_params[param_name] = default_value</ins> @ignore_warnings(category=(DeprecationWarning, FutureWarning)) def check_classifiers_regression_target(name, estimator_orig):     # Check if classifier throws an exception when fed regression targets


Question: self.n_jobs = n_jobs      def _fit_transform(self, X):        X = check_array(X)        X = check_array(X, accept_sparse='csr')         self.nbrs_ = NearestNeighbors(n_neighbors=self.n_neighbors,                                       algorithm=self.neighbors_algorithm,                                       n_jobs=self.n_jobs)diff --git a/sklearn/manifold/locally_linear.py b/sklearn/manifold/locally_linear.py-- a/sklearn/manifold/locally_linear.py++ b/sklearn/manifold/locally_linear.py

Isomap and LocallyLinearEmbedding do not accept sparse matrix input (contrary to documentation) The mentions that should support sparse matrix. The error comes from the 5 of from . If documentation is correct should be called with  I can submit a PR. also accepts sparse matrix according to documentation on and methods. Given that also uses the arpack solver, I guess that it also should accept sparse matrices. Check of checkarray calls in the manifold subfolder For reference, my backtrace


Question: Parameters     ----------    X : {array-like, sparse matrix, BallTree, KDTree, NearestNeighbors}    X : {array-like, NearestNeighbors}         Sample data, shape = (n_samples, n_features), in the form of a        numpy array, sparse array, precomputed tree, or NearestNeighbors        object.        numpy array or a NearestNeighbors object.      n_neighbors : int         Number of neighbors for each sample.


Question: Parameters     ----------    X : {array-like, sparse matrix, BallTree, KDTree, NearestNeighbors}    X : {array-like, NearestNeighbors}         Sample data, shape = (n_samples, n_features), in the form of a        numpy array, sparse array, precomputed tree, or NearestNeighbors        object.        numpy array or a NearestNeighbors object.      n_neighbors : integer         number of neighbors to consider for each point.


Question: else:         raise ValueError("Algorithm must be 'auto', 'full' or 'elkan', got"                          " %s" % str(algorithm))    seeds = random_state.randint(np.iinfo(np.int32).max, size=n_init)     if effective_n_jobs(n_jobs) == 1:         # For a single thread, less memory is needed if we just store one set         # of the best results (as opposed to one set per run per thread).        for it in range(n_init):        for seed in seeds:             # run a k-means once             labels, inertia, centers, n_iter_ = kmeans_single(                 X, sample_weight, n_clusters, max_iter=max_iter, init=init,                 verbose=verbose, precompute_distances=precompute_distances,                 tol=tol, x_squared_norms=x_squared_norms,                random_state=random_state)                random_state=seed)             # determine if these results are the best so far             if best_inertia is None or inertia < best_inertia:                 best_labels = labels.copy()

KMeans gives slightly different result for njobs=1 vs. njobs 1 <!-- If your issue is a usage question, submit it here instead: StackOverflow with the scikit-learn tag: Mailing List: For more information, see User Questions: http://scikit- --<!-- Instructions For Filing a Bug: --<!-- Example: Joblib Error thrown when calling fit on LatentDirichletAllocation with evaluateevery 0--I noticed that gives a slightly different result depending on if or . <!-- Example: If the code is too long, feel free to put it in a public gist and link it in the issue: --Below is the code I used to run the same clustering on a varying number of jobs. <!-- Example: No error is thrown. Please paste or describe the expected results.--Should expect the the clustering result (e.g. the inertia) to be the same regardless of how many jobs are run in parallel. <!-- Please paste or specifically describe the actual output or traceback. --The case has a (slightly) different inertia than the parallel cases. <!-- Please run the following snippet and paste the output below. import platform; print(platform.platform()) import sys; print("Python", sys.version) import numpy; print("NumPy", numpy.version) import scipy; print("SciPy", scipy.version) import sklearn; print("Scikit-Learn", sklearn.version) --Darwin-16.7.0-x86_64-i386-64bit Python 3.6.1 (default, May 11 2017, 13:04:09) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] NumPy 1.13.1 SciPy 0.19.1 Scikit-Learn 0.20.dev0 <!-- Thanks for contributing! --


Question: best_n_iter = n_iter_     else:         # parallelisation of k-means runs<del>        seeds = random_state.randint(np.iinfo(np.int32).max, size=n_init)</del>         results = Parallel(n_jobs=n_jobs, verbose=0)(             delayed(kmeans_single)(X, sample_weight, n_clusters,                                    max_iter=max_iter, init=init,


Question: return last_step.fit(Xt, y, **fit_params).transform(Xt)      @if_delegate_has_method(delegate='_final_estimator')    def predict(self, X):    def predict(self, X, **predict_params):         """Apply transforms to the data, and predict with the final estimator          Parameters

Bug: the predict method of Pipeline object does not use the exact predict method of final step estimator I am trying to use Pipeline with a customized final step estimator. This final estimator predict method can output std when using returnstd=True. But the predict method of Pipeline does not allow returnstd option, gives error on scikit- Line 54. In the user guide:user guide http://scikit- says the following, but the predict method in Pipeline is not the same as that in final estimator """ Calling fit on the pipeline is the same as calling fit on each estimator in turn, transform the input and pass it on to the next step. The pipeline has all the methods that the last estimator in the pipeline has, i.e. if the last estimator is a classifier, the Pipeline can be used as a classifier. If the last estimator is a transformer, again, so is the pipeline. """


Question: Data to predict on. Must fulfill input requirements of first step             of the pipeline. <ins>        **predict_params : dict of string -> object            Parameters to the ``predict`` called at the end of all            transformations in the pipeline. Note that while this may be            used to return uncertainties from some models with return_std            or return_cov, uncertainties that are generated by the            transformations in the pipeline are not propagated to the            final estimator.</ins>         Returns         -------         y_pred : array-like


Question: for name, transform in self.steps[:-1]:             if transform is not None:                 Xt = transform.transform(Xt)        return self.steps[-1][-1].predict(Xt)        return self.steps[-1][-1].predict(Xt, **predict_params)      @if_delegate_has_method(delegate='_final_estimator')     def fit_predict(self, X, y=None, **fit_params):


Question: #   http://cseweb.ucsd.edu/~lvdmaaten/workshops/nips2010/papers/vandermaaten.pdf from __future__ import division <ins>import warnings</ins> from time import time import numpy as np from scipy import linalg

sklearn.manifold.t_sne.trustworthiness should allow custom metric boolean parameter should be replaced by more standard .


Question: return p, error, i  def trustworthiness(X, X_embedded, n_neighbors=5, precomputed=False):def trustworthiness(X, X_embedded, n_neighbors=5,                    precomputed=False, metric='euclidean'):     r"""Expresses to what extent the local structure is retained.      The trustworthiness is within [0, 1]. It is defined as


Question: precomputed : bool, optional (default: False)         Set this flag if X is a precomputed square distance matrix.         ..deprecated:: 0.20            ``precomputed`` has been deprecated in version 0.20 and will be            removed in version 0.22. Use ``metric`` instead.    metric : string, or callable, optional, default 'euclidean'        Which metric to use for computing pairwise distances between samples        from the original input space. If metric is 'precomputed', X must be a        matrix of pairwise distances or squared distances. Otherwise, see the        documentation of argument metric in sklearn.pairwise.pairwise_distances        for a list of available metrics.     Returns     -------     trustworthiness : float         Trustworthiness of the low-dimensional embedding.     """     if precomputed:        dist_X = X    else:        dist_X = pairwise_distances(X, squared=True)        warnings.warn("The flag 'precomputed' has been deprecated in version "                      "0.20 and will be removed in 0.22. See 'metric' "                      "parameter instead.", DeprecationWarning)        metric = 'precomputed'    dist_X = pairwise_distances(X, metric=metric)     ind_X = np.argsort(dist_X, axis=1)     ind_X_embedded = NearestNeighbors(n_neighbors).fit(X_embedded).kneighbors(         return_distance=False)


Question: coef_ : array, shape (1, n_features) or (n_classes, n_features)         Coefficient of the features in the decision function.         `coef_` is of shape (1, n_features) when the given problem        is binary.        `coef_` is of shape (1, n_features) when the given problem is binary.        In particular, when `multi_class='multinomial'`, `coef_` corresponds        to outcome 1 (True) and `-coef_` corresponds to outcome 0 (False).      intercept_ : array, shape (1,) or (n_classes,)         Intercept (a.k.a. bias) added to the decision function.          If `fit_intercept` is set to False, the intercept is set to zero.        `intercept_` is of shape(1,) when the problem is binary.        `intercept_` is of shape (1,) when the given problem is binary.        In particular, when `multi_class='multinomial'`, `intercept_`        corresponds to outcome 1 (True) and `-intercept_` corresponds to        outcome 0 (False).      n_iter_ : array, shape (n_classes,) or (1, )         Actual number of iterations for all classes. If binary or multinomial,

Incorrect predictions when fitting a LogisticRegression model on binary outcomes with . Incorrect predictions when fitting a LogisticRegression model on binary outcomes with . <!-- Example: Joblib Error thrown when calling fit on LatentDirichletAllocation with evaluateevery 0--<!-- Example: If the code is too long, feel free to put it in a public gist and link it in the issue: --If we compare against R or using , the log loss (which is approximately proportional to the objective function as the regularisation is set to be negligible through the choice of ) is incorrect. We expect the log loss to be roughly The actual log loss when using is . See the stack exchange question for more information. The issue it seems is caused in In the case even if we cannot reduce to a 1D case by throwing away one of the vectors of coefficients (as we can in normal binary logistic regression). This is essentially a difference between softmax (redundancy allowed) and logistic regression. This can be fixed by commenting out the lines 762 and 763. I am apprehensive however that this may cause some other unknown issues which is why I am positing as a bug. <!-- Please run the following snippet and paste the output below. import platform; print(platform.platform()) import sys; print("Python", sys.version) import numpy; print("NumPy", numpy.version) import scipy; print("SciPy", scipy.version) import sklearn; print("Scikit-Learn", sklearn.version) --Linux-4.10.0-33-generic-x8664-with-Ubuntu-16.04-xenial Python 3.5.2 (default, Nov 17 2016, 17:05:23) NumPy 1.13.1 SciPy 0.19.1 Scikit-Learn 0.19.0 <!-- Thanks for contributing! --


Question: """         if not hasattr(self, "coef_"):             raise NotFittedError("Call fit before prediction")        calculate_ovr = self.coef_.shape[0] == 1 or self.multi_class == "ovr"        if calculate_ovr:        if self.multi_class == "ovr":             return super(LogisticRegression, self)._predict_proba_lr(X)         else:            return softmax(self.decision_function(X), copy=False)            decision = self.decision_function(X)            if decision.ndim == 1:                # Workaround for multi_class="multinomial" and binary outcomes                # which requires softmax prediction with only a 1D decision.                decision_2d = np.c_[-decision, decision]            else:                decision_2d = decision            return softmax(decision_2d, copy=False)      def predict_log_proba(self, X):         """Log of probability estimates.


Question: deprecated: bool  def type_to_xref(target: str, env: BuildEnvironment = None, suppress_prefix: bool = False                 ) -> addnodes.pending_xref:    """Convert a type string to a cross reference node."""    if target == 'None' or target.startswith('typing.'):def parse_reftarget(reftarget: str, suppress_prefix: bool = False                    ) -> Tuple[str, str, str, bool]:    """Parse a type string and return (reftype, reftarget, title, refspecific flag)"""    refspecific = False    if reftarget.startswith('.'):        reftarget = reftarget[1:]        title = reftarget        refspecific = True    elif reftarget.startswith('~'):        reftarget = reftarget[1:]        title = reftarget.split('.')[-1]    elif suppress_prefix:        title = reftarget.split('.')[-1]    elif reftarget.startswith('typing.'):        title = reftarget[7:]    else:        title = reftarget    if reftarget == 'None' or reftarget.startswith('typing.'):         # typing module provides non-class types.  Obj reference is good to refer them.         reftype = 'obj'     else:         reftype = 'class'     return reftype, reftarget, title, refspecificdef type_to_xref(target: str, env: BuildEnvironment = None, suppress_prefix: bool = False                 ) -> addnodes.pending_xref:    """Convert a type string to a cross reference node."""     if env:         kwargs = {'py:module': env.ref_context.get('py:module'),                   'py:class': env.ref_context.get('py:class')}     else:         kwargs = {}     refspecific = False    if target.startswith('.'):        target = target[1:]        text = target        refspecific = True    elif target.startswith('~'):        target = target[1:]        text = target.split('.')[-1]    elif suppress_prefix:        text = target.split('.')[-1]    elif target.startswith('typing.'):        text = target[7:]    else:        text = target    reftype, target, title, refspecific = parse_reftarget(target, suppress_prefix)      if env.config.python_use_unqualified_type_names:         # Note: It would be better to use qualname to describe the object to support support         # nested classes.  But python domain can't access the real python object because this         # module should work not-dynamically.        shortname = text.split('.')[-1]        shortname = title.split('.')[-1]         contnodes: List[Node] = [pending_xref_condition('', shortname, condition='resolved'),                                 pending_xref_condition('', text, condition='*')]                                 pending_xref_condition('', title, condition='*')]     else:        contnodes = [nodes.Text(text)]        contnodes = [nodes.Text(title)]      return pending_xref('', *contnodes,                         refdomain='py', reftype=reftype, reftarget=target,

autodocunqualifiedtypehints does not work well with autodoctypehints="description" autodocunqualifiedtypehints does not work well with autodoctypehints="description". Typehints in info-field-list are also changed to the short style when autodocunqualifedtypehints enabled. N/A No response Mac 10.1 HEAD of 4.x autodoc No response No response


Question: result = super().make_xref(rolename, domain, target,  # type: ignore                                    innernode, contnode,                                    env, inliner=None, location=None)        result['refspecific'] = True        result['py:module'] = env.ref_context.get('py:module')        result['py:class'] = env.ref_context.get('py:class')        if target.startswith(('.', '~')):            prefix, result['reftarget'] = target[0], target[1:]            if prefix == '.':                text = target[1:]            elif prefix == '~':                text = target.split('.')[-1]            for node in list(result.traverse(nodes.Text)):                node.parent[node.parent.index(node)] = nodes.Text(text)                break        elif isinstance(result, pending_xref) and env.config.python_use_unqualified_type_names:            children = result.children            result.clear()            shortname = target.split('.')[-1]            textnode = innernode('', shortname)            contnodes = [pending_xref_condition('', '', textnode, condition='resolved'),                         pending_xref_condition('', '', *children, condition='*')]            result.extend(contnodes)        if isinstance(result, pending_xref):            result['refspecific'] = True            result['py:module'] = env.ref_context.get('py:module')            result['py:class'] = env.ref_context.get('py:class')            reftype, reftarget, reftitle, _ = parse_reftarget(target)            if reftarget != reftitle:                result['reftype'] = reftype                result['reftarget'] = reftarget                result.clear()                result += innernode(reftitle, reftitle)            elif env.config.python_use_unqualified_type_names:                children = result.children                result.clear()                shortname = target.split('.')[-1]                textnode = innernode('', shortname)                contnodes = [pending_xref_condition('', '', textnode, condition='resolved'),                             pending_xref_condition('', '', *children, condition='*')]                result.extend(contnodes)          return result


Question: class PyField(PyXrefMixin, Field):    def make_xref(self, rolename: str, domain: str, target: str,                  innernode: Type[TextlikeNode] = nodes.emphasis,                  contnode: Node = None, env: BuildEnvironment = None,                  inliner: Inliner = None, location: Node = None) -> Node:        if rolename == 'class' and target == 'None':            # None is not a type, so use obj role instead.            rolename = 'obj'        return super().make_xref(rolename, domain, target, innernode, contnode,                                 env, inliner, location)    pass   class PyGroupedField(PyXrefMixin, GroupedField):


Question: class PyTypedField(PyXrefMixin, TypedField):    def make_xref(self, rolename: str, domain: str, target: str,                  innernode: Type[TextlikeNode] = nodes.emphasis,                  contnode: Node = None, env: BuildEnvironment = None,                  inliner: Inliner = None, location: Node = None) -> Node:        if rolename == 'class' and target == 'None':            # None is not a type, so use obj role instead.            rolename = 'obj'        return super().make_xref(rolename, domain, target, innernode, contnode,                                 env, inliner, location)    pass   class PyObject(ObjectDescription[Tuple[str, str]]):diff --git a/sphinx/ext/autodoc/typehints.py b/sphinx/ext/autodoc/typehints.py-- a/sphinx/ext/autodoc/typehints.py++ b/sphinx/ext/autodoc/typehints.py


Question: def record_typehints(app: Sphinx, objtype: str, name: str, obj: Any,                      options: Dict, args: str, retann: str) -> None:     """Record type hints to env object."""<ins>    if app.config.autodoc_typehints_format == 'short':        mode = 'smart'    else:        mode = 'fully-qualified'</ins>     try:         if callable(obj):             annotations = app.env.temp_data.setdefault('annotations', {})


Question: sig = inspect.signature(obj, type_aliases=app.config.autodoc_type_aliases)             for param in sig.parameters.values():                 if param.annotation is not param.empty:                    annotation[param.name] = typing.stringify(param.annotation)                    annotation[param.name] = typing.stringify(param.annotation, mode)             if sig.return_annotation is not sig.empty:                annotation['return'] = typing.stringify(sig.return_annotation)                annotation['return'] = typing.stringify(sig.return_annotation, mode)     except (TypeError, ValueError):         pass


Question: node.parent.hasattr('ids') and node.parent['ids']):             # add permalink anchor             if close_tag.startswith('</h'):                self.add_permalink_ref(node.parent, _('Permalink to this headline'))                self.add_permalink_ref(node.parent, _('Permalink to this heading'))             elif close_tag.startswith('</h'):                 self.body.append('%s' % (                                     _('Permalink to this headline'),                                     _('Permalink to this heading'),                                      self.config.html_permalinks_icon))             elif isinstance(node.parent, nodes.table):                 self.body.append('')diff --git a/sphinx/writers/html5.py b/sphinx/writers/html5.py-- a/sphinx/writers/html5.py++ b/sphinx/writers/html5.py

Change "Permalink to this headline" to use "heading" instead Sphinx-generated tooltips for headings use "Headline" instead of "Heading". Picking out of Build any Sphinx documentation, containing one or more headings (eg: ). When hovering over the Sphinx-injected "headerlink", notice that it says "Headline" instead of "Heading". Instead of: Permalink to this headline The tooltip should be: Permalink to this heading <img width="235" alt="Screenshot 2022-01-01 at 17 20 09" src="https://user-"N/A N/A No response No response The relevant chunk of code: This will also need some update to the translated strings, which means that this will likely need to be a Sphinx 5.0+ change?


Question: node.parent.hasattr('ids') and node.parent['ids']):             # add permalink anchor             if close_tag.startswith('</h'):                self.add_permalink_ref(node.parent, _('Permalink to this headline'))                self.add_permalink_ref(node.parent, _('Permalink to this heading'))             elif close_tag.startswith('</h'):                 self.body.append('%s' % (                                     _('Permalink to this headline'),                                     _('Permalink to this heading'),                                      self.config.html_permalinks_icon))             elif isinstance(node.parent, nodes.table):                 self.body.append('')


Question: descr = _('%s command line option') % currprogram         else:             descr = _('command line option')        for option in sig.split(', '):        for option in signode.get('allnames', []):             entry = '; '.join([descr, option])             self.indexnode['entries'].append(('pair', entry, signode['ids'][0], '', None))

Latex: long option name overflows in Index Let's consider something like: Leads to the following with . ! Build snippet. No response Build the snippet No response Linux 8 0 No response No response No response


Question: uri_pattern = re.compile(re.escape(base_uri).replace('%s', '(?P<value>.+)'))              match = uri_pattern.match(uri)            if match and match.groupdict().get('value'):            if (                match and                match.groupdict().get('value') and                '/' not in match.groupdict()['value']            ):                 # build a replacement suggestion                 msg = __('hardcoded link %r could be replaced by an extlink '                          '(try using %r instead)')

Allow to bail out extlink replacement suggestion Feature via Consider the following ext link: and the following text: ` Can we somehow bailout out the check here, or perhaps the suggestion should only apply if there's no in the extlink, what do you think? cc


Question: def visit_footnote(self, node: Element) -> None:         self.in_footnote += 1         label = cast(nodes.label, node[0])        if 'referred' in node:            self.body.append(r'\sphinxstepexplicit ')         if self.in_parsed_literal:             self.body.append(r'\begin{footnote}[%s]' % label.astext())         else:             self.body.append('%' + CR)             self.body.append(r'\begin{footnote}[%s]' % label.astext())         if 'referred' in node:            self.body.append(r'\phantomsection'                             r'\label{\thesphinxscope.%s}%%' % label.astext() + CR)            # TODO: in future maybe output a latex macro with backrefs here            pass         self.body.append(r'\sphinxAtStartFootnote' + CR)      def depart_footnote(self, node: Element) -> None:

Alternating multiply referred footnotes produce a ? in pdf output In some circumstances footnote mark is rendered as and there is no hyperlink file : then . Footnotes are rendered correctly See above code ! Mac 7 (CPython) 0 and current 4.x (v4.5.0+/) No response No response No response


Question: def visit_footnotetext(self, node: Element) -> None:         label = cast(nodes.label, node[0])         self.body.append('%' + CR)        self.body.append(r'\begin{footnotetext}[%s]'                         r'\phantomsection\label{\thesphinxscope.%s}%%'                         % (label.astext(), label.astext()) + CR)        self.body.append(r'\begin{footnotetext}[%s]' % label.astext())         self.body.append(r'\sphinxAtStartFootnote' + CR)      def depart_footnotetext(self, node: Element) -> None:


Question: return stringify_signature(sig, show_return_annotation=False, **kwargs) <ins>    def _find_signature(self) -> Tuple[str, str]:        result = super()._find_signature()        if result is not None:            # Strip a return value from signature of constructor in docstring (first entry)            result = (result[0], None)        for i, sig in enumerate(self._signatures):            if sig.endswith(' -> None'):                # Strip a return value from signatures of constructor in docstring (subsequent                # entries)                self._signatures[i] = sig[:-8]        return result</ins>     def format_signature(self, **kwargs: Any) -> str:         if self.doc_as_attr:             return ''

Overridden, overloaded class docstring return type rendered as None Some overloaded class definitions show ` as a return type, when there shouldn't be any return type. This seems to happen when the overloaded functions are overridden in the final docstring. A class without this problem is also provided for comparison. Exactly the same as ! ! Ubuntu 3 0 '', '', 'sphinxrtdtheme' No response Related Sphinx issue: This was originally reported in


Question: kw_defaults = list(function.args.kw_defaults)             parameters = list(sig.parameters.values())             for i, param in enumerate(parameters):                if param.default is not param.empty:                if param.default is param.empty:                    if param.kind == param.KEYWORD_ONLY:                        # Consume kw_defaults for kwonly args                        kw_defaults.pop(0)                else:                     if param.kind in (param.POSITIONAL_ONLY, param.POSITIONAL_OR_KEYWORD):                         default = defaults.pop(0)                         value = get_default_value(lines, default)

autodocpreservedefaults=True does not work for mixture of keyword only arguments with/without defaults If I understand correctly, the following is a valid signature of a class method: When documenting this with autodoc and , generates a with for the arguments. This later raises an exception in since the dunder method now returns instead of a string. Basically what happens is that ast generates a value in the of the since the first keyword argument is required, but simply ignores that argument because the is empty. This leaves the in the to be picked up when the keyword argument with default value is processed -- instead of the actual default. This can't be resolved by the call which therefore simply returns , which ends up as the of the . Imo this could simply be resolved by ing the corresponding from the if a parameter with empty is encountered. Create a module with contents and auto-document while setting in your Make sure sphinx tries to document all parameters, (since it's a method, they will be documented when the autodoc directive has , if you try the same with a module level method you need to document the parameters) The correct default value should be documented. The Warning Message also is pretty worthless (probably the value should not be formatted with a simple but instead with a ?) Any Tested with versions 3.8 0


Question: self.start_filter,                        self.end_filter,                        self.lines_filter,                       self.dedent_filter,                        self.prepend_filter,                       self.append_filter,                       self.dedent_filter]                       self.append_filter]             lines = self.read_file(self.filename, location=location)             for func in filters:                 lines = func(lines, location=location)

Use of literalinclude prepend results in incorrect indent formatting for code eamples Cannot determine a mechanism to use literalinclude directive with or to match code example indentation, as leading whitespace is removed. Example of including xml snippet, that should be prefixed with . File: File : Produces the following valid xml, which is indented poorly: I cannot think of good warning free way to indent to match the included code example. Expect leading white space to be preserved in output: No response Mac 10 0 ['', ''] No response Using creatively almost provides a workaround: Produces a warning, which fails the build with build policy. Use of could be a good solution, if was applied only to the literalinclude and not to the and content.


Question: return {x.strip() for x in arg.split(',') if x.strip()}  def inherited_members_option(arg: Any) -> Union[object, Set[str]]:def inherited_members_option(arg: Any) -> Set[str]:     """Used to convert the :members: option to auto directives."""     if arg in (None, True):        return 'object'        return {'object'}    elif arg:        return set(x.strip() for x in arg.split(','))     else:        return arg        return set()   def member_order_option(arg: Any) -> Optional[str]:

inherited-members should support more than one class Is your feature request related to a problem? Please describe. I have two situations: A class inherits from multiple other classes. I want to document members from some of the base classes but ignore some of the base classes A module contains several class definitions that inherit from different classes that should all be ignored (e.g., classes that inherit from list or set or tuple). I want to ignore members from list, set, and tuple while documenting all other inherited members in classes in the module. Describe the solution you'd like The :inherited-members: option to automodule should accept a list of classes. If any of these classes are encountered as base classes when instantiating autoclass documentation, they should be ignored. Describe alternatives you've considered The alternative is to not use automodule, but instead manually enumerate several autoclass blocks for a module. This only addresses the second bullet in the problem description and not the first. It is also tedious for modules containing many class definitions.


Question: ``autodoc-skip-member`` event.         """         def is_filtered_inherited_member(name: str, obj: Any) -> bool:            inherited_members = self.options.inherited_members or set()             if inspect.isclass(self.object):                 for cls in self.object.__mro__:                    if cls.__name__ == self.options.inherited_members and cls != self.object:                    if cls.__name__ in inherited_members and cls != self.object:                         # given member is a member of specified *super class*                         return True                     elif name in cls.__dict__: