Skip to main content

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 to Auto 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. For Date, Time_Of_Day and Date_Time, a Java date time style can be used. For Boolean, it should be two values that represent true and false, separated by a |. Alternatively, a Data_Formatter can be passed to provide complete customisation of the formatting. If Nothing 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 the on_problems settings. Defaults to True.
  • 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, a Missing_Input_Columns is raised as an error, unless error_on_missing_columns is set to False, in which case the problem is reported according to the on_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.