Field¶
field/column/element objects
This submodule contains the various field type objects that are used to define the fields (i.e. columns, elements) that make up a tabular data set. These field objects can be extended by adding additional rules in the rules keyword of the fields constructor. Additional modification, including the definition of entirely new field types can be achieved by subclassing the Field base class.
All field subclasses pass their keyword arguments to the base Field class. See documentation for the base Field for a complete listing of optional keyword arguments, including rules extension.
See the rumydata.rules submodule to learn more about the use of rules to extend field class behavior.
-
class
rumydata.field.Ignore¶ Bases:
rumydata.field.FieldIgnore the values found in this field. This will cause other dependencies (like row checks) to treat any values in this field as if they were empty. While the check method still exists, this class overwrites those inherited methods to intentionally have no effect.
-
class
rumydata.field.Empty(**kwargs)¶ Bases:
rumydata.field.FieldEmpty Field
A field which must be entirely empty/blank/null. This differs from the Ignore field in that it will raise errors if any values are found.
-
class
rumydata.field.Text(max_length, min_length=None, **kwargs)¶ Bases:
rumydata.field.FieldText Field
A field made up entirely of text. This is one of the least restrictive field types, enforcing only a maximum and (optional) minimum length.
Parameters: - max_length – the maximum number of allowable characters
- min_length – (optional) the minimum number of allowable characters
-
class
rumydata.field.Date(min_date: str = None, max_date: str = None, **kwargs)¶ Bases:
rumydata.field.FieldDate field
A date value formatted in ISO-8601 (YYYY-MM-DD). Rules can be applied to restrict minimum and maximum date. If your date string includes, or might include an empty timestamp (00:00:00), the truncate_time parameter can be used to remove this empty timestamp prior to validation, preventing it from causing failure.
Parameters: - min_date – the minimum date value allowed
- max_date – the maximum date value allowed
-
class
rumydata.field.Currency(significant_digits: int, precision: int = 2, **kwargs)¶ Bases:
rumydata.field.FieldCurrency field
A numeric field which represents a currency value. Defaults to a maximum of two decimal points.
Parameters: significant_digits – an integer which specifies the maximum number of decimals that are allowed in the value.
-
class
rumydata.field.Digit(max_length, min_length=None, **kwargs)¶ Bases:
rumydata.field.FieldDigit field
A value made up entirely of digits (numbers). The main difference between this field and an Integer, is that this field will allow leading zeroes (e.g 0123), while an Integer would not.
Parameters: - max_length – the maximum number of digits
- min_length – (optional) the minimum number of digits
-
class
rumydata.field.Integer(max_length, min_length=None, **kwargs)¶ Bases:
rumydata.field.FieldInteger field
A value made up entirely of digits (numbers). A whole number.
Parameters: - max_length – the maximum number of digits
- min_length – (optional) the minimum number of digits
-
class
rumydata.field.Choice(valid_values: list, case_insensitive=False, **kwargs)¶ Bases:
rumydata.field.FieldChoice field
A field with one of a pre-defined set of values.
Parameters: - valid_values – a list of values which are considered valid
- case_insensitive – a boolean control which defaults to False, making the check of valid values case sensitive.
-
class
rumydata.field.Field(nullable=False, rules: list = None, **kwargs)¶ Base Field class
This class provides the framework for the definition of field types in this package.
Parameters: - nullable – a boolean indicator which controls whether the field can be null (blank). Defaults to False, which will cause errors to be raised when checking empty strings.
- rules – a list of rules to apply to this field during checks.
- strip – (optional) apply pre-processing to values in the field which applies the str.strip method, removing leading and trailing whitespaces, prior to checking rules.
-
check_cell(value: Union[str, Tuple[str, Dict[KT, VT]]], **kwargs)¶ Cell Rule assertion
Perform an assertion of the provided cell value against the rules defined for the field. If the value fails the check for any of the rules, the assertion will raise a detailed exception message.
Parameters: value – a cell value, either a string or a tuple of a string and a dictionary, to be checked.
-
check_column(values: List[str], **kwargs)¶ Column Rule assertion
Perform an assertion of the provided column values against the rules defined for the field. If the values fail the check for any of the rules, the assertion will raise a detailed exception message.
Parameters: values – a list of values contained in the column.