assert_all_finite#

sklearn.utils.assert_all_finite(X,*,allow_nan=False,estimator_name=None,input_name='')[source]#

Throw a ValueError if X contains NaN or infinity.

Parameters:
X{ndarray, sparse matrix}

The input data.

allow_nanbool, default=False

If True, do not throw error whenX contains NaN.

estimator_namestr, default=None

The estimator name, used to construct the error message.

input_namestr, default=””

The data name used to construct the error message. In particularifinput_name is “X” and the data has NaN values andallow_nan is False, the error message will link to the imputerdocumentation.

Examples

>>>fromsklearn.utilsimportassert_all_finite>>>importnumpyasnp>>>array=np.array([1,np.inf,np.nan,4])>>>try:...assert_all_finite(array)...print("Test passed: Array contains only finite values.")...exceptValueError:...print("Test failed: Array contains non-finite values.")Test failed: Array contains non-finite values.
On this page

This Page