Table.auto_cast
auto_castcolumnsshrink_typeserror_on_missing_columnson_problems
Group: Conversions
Aliases: auto_value_types
Documentation
Automatically detect the appropriate data type and size for specified columns and change them, based on the contents. This is most useful for Mixed types to narrow down the type if all values could fit into one type.
Returns - A new table with the specified columns converted to the most appropriate type.
Arguments
columns: The selection of columns to convert. Defaults to all columns.shrink_types: If setTrue, smaller types will be chosen if possible, according to the rules below. Defaults toFalse. For example, from a 64-bit integer to a 32-bit integer if all fit.error_on_missing_columns: Specifies if a missing input column should result in an error regardless of theon_problemssettings. Defaults toTrue.on_problems: Specifies how to handle problems if they occur, reporting them as warnings by default.
Remarks
Auto Type Selection Rules
- If a
Mixedcolumn can be assigned a single type, likeCharorInteger, that will be used. - Text columns are not parsed. To do that, use the
parsemethod. - If a
Floatcolumn contains only integers, it will be converted to an Integer column. - If a
Decimalcolumn contains only integers that could fit in a 64-bit integer storage, it will be converted to an Integer column. - If
shrink_typesisFalse(default), no other transformations are applied. - However, if
shrink_typesis set toTrue, then:- Integer columns will be assigned the smallest size that can fit all
values (down to 16-bit integers; converting to the
Bytetype has to be done manually throughcast). - If all elements in a text column have the same length, the type will become fixed length.
- Otherwise, if a text column is variable length, but all text elements are no longer than 255 characters, the column will get a max length of 255. Otherwise, the column size limit will stay unchanged.
- Integer columns will be assigned the smallest size that can fit all
values (down to 16-bit integers; converting to the