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_problems
settings. 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
Mixed
column can be assigned a single type, likeChar
orInteger
, that will be used. - Text columns are not parsed. To do that, use the
parse
method. - If a
Float
column contains only integers, it will be converted to an Integer column. - If a
Decimal
column contains only integers that could fit in a 64-bit integer storage, it will be converted to an Integer column. - If
shrink_types
isFalse
(default), no other transformations are applied. - However, if
shrink_types
is set toTrue
, then:- Integer columns will be assigned the smallest size that can fit all
values (down to 16-bit integers; converting to the
Byte
type 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