nan_mask_string#

pybear.utilities.nan_mask_string(X)#

In all cases, return an identically shaped boolean numpy array or vector indicating the locations of nan-like representations in the data.

“nan-like representations” include, at least, pandas.NA, pandas.NaT, None (of type None, not string “None”), and string representations of “nan”. This function does not accept scipy sparse matrices or arrays, as dok and lil formats are not handled globally in the nan_mask functions, and the remaining sparse objects can only contain numeric data.

This function accepts Python lists, tuples, and sets, numpy arrays, pandas dataframes and series, and polars dataframes and series. It does not accept any ragged Python built-ins, numpy recarrays, or numpy masked arrays.

Parameters:
XPythonTypes | NumpyTypes | PandasTypes | PolarsTypes

shape (n_samples, n_features) or (n_samples,)

The object for which to locate nan-like representations.

Returns:
masknumpy.ndarray[bool] of shape (n_samples, n_features) or (n_samples)

Indicates nan-like representations in X via the value boolean True. Values that are not nan-like are False.

Notes

Type Aliases

PythonTypes:

list | tuple | set | list[list] | tuple[tuple]]

NumpyTypes:

numpy.ndarray

PandasTypes:

pandas.DataFrame | pandas.Series

PolarsTypes:

polars.DataFrame | polars.Series

Examples

>>> from pybear.utilities import nan_mask_string
>>> X = list('abcde')
>>> X[0] = 'nan'
>>> X[2] = 'nan'
>>> X
['nan', 'b', 'nan', 'd', 'e']
>>> nan_mask_string(X)
array([ True, False,  True, False, False])