is_sparse_feasible#
- caf.toolkit.pandas_utils.is_sparse_feasible(df, dimension_cols, warning_action='default')[source]#
Check whether a sparse array is more efficient than a dense one.
- Parameters:
df (DataFrame) – The potential dataframe to convert.
dimension_cols (Collection[Any]) – The columns of df that define the dimensions (the non-value columns).
warning_action (Literal['default', 'error', 'ignore', 'always', 'module', 'once']) – How to handle errors if a sparse matrix is not a feasible option to reduce memory. This argument will be passed directly to warnings.filterwarnings(warning_action). See https://docs.python.org/3/library/warnings.html for more information.
- Returns:
True if memory would be saved by converting to a sparse matrix rather than a dense one. Otherwise, False.
- Return type:
boolean
- Raises:
RuntimeWarning: – If a sparse matrix is not a feasible option and warning_action=”error”.