infer_stypes#
- sdm.infer_stypes(table: pa.Table | pd.DataFrame | cudf.DataFrame, overrides: Mapping[str, StypeLike] | None = None, *, text: Literal['off', 'infer', 'drop'] = 'off', id: Literal['off', 'infer', 'drop'] = 'off', unsupported: Literal['error', 'warn', 'drop'] = 'error') dict[str, StypeLike]#
Infer semantic types from raw data statistics.
Semantic types are inferred as follows:
Integer, floating-point, and decimal columns are inferred as
numerical.String, boolean and dictionary-encoded columns are inferred as
categorical.Datetime columns are inferred as
datetime.
Optionally, infer the following semantic types based on best-effort heuristics:
String columns are inferred as
textif they contain at least 200 distinct string values, a distinct non-null value ratio of at least 5%, and an average of at least3words per distinct value.Integer or (non-dictionary) string columns are inferred as
idif its name contains"id"as a whole word (e.g.,"user_id","userId","id", but not"solid"or"covid").
- Parameters:
table (pa.Table | pd.DataFrame | cudf.DataFrame) – A
pandas.DataFrame,pyarrow.Table, orcudf.DataFrame.overrides (Mapping[str, StypeLike] | None) – Optional semantic type overrides by column name.
text (Literal['off', 'infer', 'drop']) – The
textdetection policy."off"disablestextcolumn detection."infer"includes inferredtextcolumns."drop"omits inferredtextcolumns.id (Literal['off', 'infer', 'drop']) – The
iddetection policy."off"disablesidcolumn detection."infer"includes inferredidcolumns."drop"omits inferredidcolumns.unsupported (Literal['error', 'warn', 'drop']) – How to handle unsupported dtypes.
"error"raises aTypeError."warn"emits a warning and omits the column."drop"omits the column silently.
- Returns:
Dictionary mapping column names to inferred semantic type.
- Return type: