Code Reference - Custom Information
df_file_interchange.ci.base
The base class for custom info is defined here.
df_file_interchange.ci.base.FIBaseCustomInfo
Bases: BaseModel
Wrapper class to store user custom info
N.B. This, and any descendent, MUST be able to deserialise based on a provided dictionary!
A descendent of this is usually supplied as an object when writing a file to include additional metadata.
Source code in df_file_interchange/ci/base.py
classname: str
property
Ensures classname is included in serialization
By defining this as a computed Pydantic attribute, it's included in any serialization.
Returns:
Type | Description |
---|---|
str
|
Our classname |
get_classname() -> str
classmethod
Returns the classname
Fairly prosaic but we use this for serialization and deserialization.
Returns:
Type | Description |
---|---|
str
|
The classname. |
df_file_interchange.ci.structured
The "standard" class for custom info is defined here along with a standard context (mostly to given an example of the format).
df_file_interchange.ci.structured.FIStructuredCustomInfo
Bases: FIBaseCustomInfo
Structured custom info
This includes extra data (applies to whole of table), and columnwise units.
The extra info and column units can, however, be different classes, i.e. the
user can inherit from FIBaseExtraInfo
or FIBaseUnit
to add more fields
to extra info or define new units, respectively. This makes matters a little
tricky when instantiating from metadata because we have to choose the
correct class to create. By default we use the classnames stored in the
metainfo and check they're a subclass of the appropriate base class. An
explicit context can, however, be passed to .model_validate()
.
Source code in df_file_interchange/ci/structured.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
|
validator_col_units(value: dict | dict[Any, FIBaseUnit], info: ValidationInfo) -> dict
classmethod
When necessary, instantiate the correct units from the supplied dict
This has to happen when supplied a dict because Pydantic needs to know what class to actually instantiate (otherwise it'll instantiate a dict of FIBaseUnit base class instead of the correct unit class).
A context can be supplied to .model_validate()
. which then appears as
info.context
here. To see the format, check
generate_default_context()
.
Source code in df_file_interchange/ci/structured.py
validator_extra_info(value: dict | FIBaseExtraInfo, info: ValidationInfo) -> FIBaseExtraInfo
classmethod
When necessary, instantiate the correct FIBaseExtraInfo from the supplied dict
This has to happen when supplied a dict because Pydantic needs to know what class to actually instantiate (otherwise it'll instantiate the FIBaseExtraInfo base class).
A context can be supplied to .model_validate()
. which then appears as
info.context
here. To see the format, check
generate_default_context()
.
Source code in df_file_interchange/ci/structured.py
df_file_interchange.ci.structured.generate_default_context()
Generates a default context that is an 'all' for anything that is included by default
Returns all available default units and FIStdExtraInfo.
If you extend with your own units, you'll have to add manually.
Returns:
Type | Description |
---|---|
dict
|
The context. |
Source code in df_file_interchange/ci/structured.py
df_file_interchange.ci.examples
Example(s) of using structured custom info. These are mostly for testing purposes but can be instructive as examples.
df_file_interchange.ci.examples.generate_example_with_metainfo_1()
Generates a sample dataframe with custom info
Returns:
Type | Description |
---|---|
tuple
|
(df, custom_info) |