Types

Note

Casting in horkos works a bit differently than in pure python. horkos acknowledges the ubiquity of CSVs as a data exchange format and has casting designed to tolerate common CSV encoding of types while still providing validation of type compatibility. In order to support this horkos provides more selective casting compared to python’s more aggressive casting.

As an example bool('False') == True in python, but would be cast to False for a boolean field in horkos. This also means that certain otherwise valid values in python will be rejected in horkos. As an example bool(42) == True, but would be rejected in horkos since 42 is a non-standard way of encoding True.

boolean:

A value that is either true or false. boolean fields will cast strings that case insensitively match "true" or "false" exactly to True and False respectively. It will cast integers 0 and 1 to False and True respectively.

float:

A numerical value with decimal components. float fields will cast integers, as well as float strings and integer strings to float values.

integer:

A whole number value. integer fields will cast integer strings to integers, they will also cast float values to integers if there is no decimal component. Float values with decimal components will fail to cast to integers.

string:

Any string value. horkos will only cast values that can be cast unambiguously to a string such as integers and floats. Other values that have a string encoding in python will not be cast to a string if there isn’t exactly one reasonable string encoding. Examples of this are booleans (since True, TRUE, and true are all equally reasonable) or dictionaries (since {'foo': 'bar'} and {"foo": "bar"} are equally reasonable).