DB_Table.parse
parsecolumnstypeformaterror_on_missing_columnson_problems
Group: Conversions
Documentation
Parses columns within a Table to a specific value type. By default, it looks at all Text
columns and attempts to deduce the type (columns with other types are not affected). In the Database backends, the default formatting settings of the particular database are used. In the in-memory backend, the default parser options only parse values where the process is reversible (e.g., 0123 would not be converted to an integer as there is a leading 0). However, settings in the Data_Formatter
can control this.
Arguments
columns
: The columns to parse. If not specified, all text columns will be parsed.type
: The type to parse the columns to. Defaults toAuto
meaning that the type will be inferred from the data. In the Database backends,Auto
is not supported, so a specific type must be selected.format
: The formatting settings to use when parsing the columns. ForDate
,Time_Of_Day
andDate_Time
, a Java date time style can be used. ForBoolean
, it should be two values that represent true and false, separated by a|
. Alternatively, aData_Formatter
can be passed to provide complete customisation of the formatting. IfNothing
is provided, the default formatting settings of the backend will be used.Nothing
is currently the only setting accepted by the Database backends.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 if a problem occurs, raising as a warning by default.
Examples
Parse dates in a column.
table.parse "birthday" Value_Type.Date
Errors
- If a column in
columns
is not in the input table, aMissing_Input_Columns
is raised as an error, unlesserror_on_missing_columns
is set toFalse
, in which case the problem is reported according to theon_problems
setting. - If a column selected for parsing is not a text column, an
Invalid_Value_Type
error is raised. - If no columns have been selected for parsing,
a
No_Input_Columns_Selected
error is raised. - If custom formatting settings were provided, but the database backend
does not support customization, an
Unsupported_Database_Operation
error is reported.