API Reference
Complete API documentation for Cobjectric.
Core Model Classes
See BaseModel Guide for detailed usage examples.
BaseModel(**kwargs)
Base class for models with typed fields.
Fields are defined as class attributes with type annotations. Fields can be accessed via the .fields attribute, which provides readonly access to Field instances.
Initialize a BaseModel instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Field values to set. Fields not provided will have MissingValue. Fields with invalid types will also have MissingValue. |
{}
|
Source code in src/cobjectric/base_model.py
1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 | |
Attributes
fields
property
Get the FieldCollection for this instance.
Returns:
| Type | Description |
|---|---|
FieldCollection
|
The FieldCollection containing all fields. |
Functions
__getitem__(path)
Get a field value by path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the field (e.g., "name", "address.city", "items[0].name"). |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The field value. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the path is invalid. |
Source code in src/cobjectric/base_model.py
__repr__()
Return a string representation of the BaseModel instance.
Format: ClassName(field1=value1, field2=MISSING, ...) Similar to Pydantic's representation style.
Returns:
| Type | Description |
|---|---|
str
|
String representation of the model. |
Source code in src/cobjectric/base_model.py
__setattr__(name, value)
Prevent setting attributes after initialization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The attribute name. |
required |
value
|
Any
|
The value to set. |
required |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If trying to set an attribute after initialization. |
Source code in src/cobjectric/base_model.py
compute_fill_rate()
Compute fill rate for all fields in this model.
Returns:
| Type | Description |
|---|---|
ModelResult
|
ModelResult containing fill rates for all fields. |
Raises:
| Type | Description |
|---|---|
DuplicateFillRateFuncError
|
If multiple fill_rate_func are defined for the same field. |
InvalidFillRateValueError
|
If a fill_rate_func returns an invalid value. |
Source code in src/cobjectric/base_model.py
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 | |
compute_fill_rate_accuracy(expected)
Compute fill rate accuracy for all fields compared to expected model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expected
|
BaseModel
|
The expected model to compare against (same type). |
required |
Returns:
| Type | Description |
|---|---|
ModelResult
|
ModelResult containing accuracy scores for all fields. |
ModelResult
|
Uses fill_rate_accuracy_weight (not fill_rate_weight) for weighted mean. |
Raises:
| Type | Description |
|---|---|
DuplicateFillRateAccuracyFuncError
|
If multiple fill_rate_accuracy_func are defined for the same field. |
InvalidFillRateAccuracyValueError
|
If a fill_rate_accuracy_func returns an invalid value. |
InvalidListCompareStrategyError
|
If list_compare_strategy is used on a non-list field. |
Source code in src/cobjectric/base_model.py
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 | |
compute_similarity(expected)
Compute similarity for all fields compared to expected model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expected
|
BaseModel
|
The expected model to compare against (same type). |
required |
Returns:
| Type | Description |
|---|---|
ModelResult
|
ModelResult containing similarity scores for all fields. |
ModelResult
|
Uses similarity_weight for weighted mean. |
Raises:
| Type | Description |
|---|---|
DuplicateSimilarityFuncError
|
If multiple similarity_func are defined for the same field. |
InvalidSimilarityValueError
|
If a similarity_func returns an invalid value. |
InvalidListCompareStrategyError
|
If list_compare_strategy is used on a non-list field. |
Source code in src/cobjectric/base_model.py
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 | |
from_dict(data)
classmethod
Create a BaseModel instance from a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any]
|
Dictionary mapping field names to values. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A new instance of the model with fields populated from the dictionary. |
Source code in src/cobjectric/base_model.py
FieldSpec(metadata=dict(), normalizer=None, fill_rate_func=not_missing_fill_rate, fill_rate_weight=1.0, fill_rate_accuracy_func=same_state_fill_rate_accuracy, fill_rate_accuracy_weight=1.0, similarity_func=exact_similarity, similarity_weight=1.0, list_compare_strategy=ListCompareStrategy.PAIRWISE)
dataclass
Specification for a field in a BaseModel.
Spec(metadata=None, normalizer=None, fill_rate_func=None, fill_rate_weight=1.0, fill_rate_accuracy_func=None, fill_rate_accuracy_weight=1.0, similarity_func=None, similarity_weight=1.0, list_compare_strategy=None)
Create a FieldSpec for a field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
dict[str, Any] | None
|
Optional metadata for the field. |
None
|
normalizer
|
AnyNormalizer | None
|
Optional normalizer function for the field. Can be a simple normalizer (1 param: value) or contextual (2 params: value, context). |
None
|
fill_rate_func
|
FillRateFunc | None
|
Optional fill rate function for the field. |
None
|
fill_rate_weight
|
float
|
Weight for fill rate computation (default: 1.0, must be >= 0.0). |
1.0
|
fill_rate_accuracy_func
|
FillRateAccuracyFunc | None
|
Optional fill rate accuracy function. |
None
|
fill_rate_accuracy_weight
|
float
|
Weight for fill rate accuracy computation (default: 1.0, must be >= 0.0). |
1.0
|
similarity_func
|
SimilarityFunc | None
|
Optional similarity function. |
None
|
similarity_weight
|
float
|
Weight for similarity computation (default: 1.0, must be >= 0.0). |
1.0
|
list_compare_strategy
|
ListCompareStrategy | str | None
|
Strategy for comparing list[BaseModel] items. Valid values: "pairwise", "levenshtein", "optimal_assignment", or ListCompareStrategy enum values. Only valid for list[BaseModel] fields (default: PAIRWISE). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
A FieldSpec instance (typed as Any for type checker compatibility). |
Raises:
| Type | Description |
|---|---|
InvalidWeightError
|
If weight is negative (< 0.0). |
ValueError
|
If list_compare_strategy is an invalid string value. |
Source code in src/cobjectric/field_spec.py
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 | |
See Field Specifications Guide for advanced customization.
Sentinel Values
MissingValue = Sentinel('MissingValue')
module-attribute
Context
FieldContext(name, field_type, spec)
dataclass
Context information passed to contextual normalizers.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The field name. |
field_type |
type
|
The declared Python type of the field. |
spec |
FieldSpec
|
The FieldSpec associated with the field. |
Field Results
See Fill Rate Guide for usage and examples.
Fill Rate Results
FieldResult(value, weight=1.0)
dataclass
Result of metric computation for a single field.
Attributes:
| Name | Type | Description |
|---|---|---|
value |
float
|
The metric value (float between 0.0 and 1.0). |
weight |
float
|
Weight for this field in weighted mean calculation (default: 1.0). |
FieldResultCollection(fields)
Collection of metric results for a model instance.
Provides attribute-based access to metric results.
Initialize a FieldResultCollection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
dict[str, FieldResult | ModelResult | ListResult]
|
Dictionary mapping field names to FieldResult, ModelResult, or ListResult instances. |
required |
Source code in src/cobjectric/results.py
Functions
__getattr__(name)
Get a metric result by field name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the field. |
required |
Returns:
| Type | Description |
|---|---|
FieldResult | ModelResult | ListResult
|
The FieldResult or ModelResult instance. |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the field does not exist. |
Source code in src/cobjectric/results.py
__getitem__(path)
Get a fill rate result by path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the field (e.g., "name", "address.city", "items[0].name"). |
required |
Returns:
| Type | Description |
|---|---|
FieldResult | ModelResult | ListResult
|
The FieldResult or ModelResult instance. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the path is invalid. |
Source code in src/cobjectric/results.py
__iter__()
__repr__()
Return a string representation of the FieldResultCollection.
ModelResult(_fields)
dataclass
Bases: StatsMixin
Result of metric computation for a model instance.
Attributes:
| Name | Type | Description |
|---|---|---|
_fields |
dict[str, FieldResult | ModelResult | ListResult]
|
Dictionary mapping field names to FieldResult, ModelResult, or ListResult instances. |
Attributes
fields
property
Get the FieldResultCollection for this result.
Returns:
| Type | Description |
|---|---|
FieldResultCollection
|
The FieldResultCollection containing all metric results. |
Functions
__add__(other)
Combine two ModelResults into a collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
'ModelResult'
|
Another ModelResult to combine. |
required |
Returns:
| Type | Description |
|---|---|
'ModelResultCollection'
|
ModelResultCollection containing both results. |
Raises:
| Type | Description |
|---|---|
IncompatibleModelResultError
|
If results come from different model types. |
Source code in src/cobjectric/results.py
__getitem__(path)
Get a fill rate result by path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the field (e.g., "name", "address.city", "items[0].name"). |
required |
Returns:
| Type | Description |
|---|---|
FieldResult | ModelResult | ListResult
|
The FieldResult or ModelResult instance. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the path is invalid. |
Source code in src/cobjectric/results.py
__repr__()
Return a string representation of the ModelResult.
to_series()
Export to pandas Series (requires cobjectric[pandas]).
Returns:
| Type | Description |
|---|---|
Any
|
pandas.Series with field paths as index and values as data. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If pandas is not installed. |
Source code in src/cobjectric/results.py
See Pandas Export Guide for exporting ModelResult to pandas Series.
Fill Rate Accuracy Results
See Fill Rate Accuracy Guide for usage and examples.
FieldResult(value, weight=1.0)
dataclass
Result of metric computation for a single field.
Attributes:
| Name | Type | Description |
|---|---|---|
value |
float
|
The metric value (float between 0.0 and 1.0). |
weight |
float
|
Weight for this field in weighted mean calculation (default: 1.0). |
FieldResultCollection(fields)
Collection of metric results for a model instance.
Provides attribute-based access to metric results.
Initialize a FieldResultCollection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
dict[str, FieldResult | ModelResult | ListResult]
|
Dictionary mapping field names to FieldResult, ModelResult, or ListResult instances. |
required |
Source code in src/cobjectric/results.py
Functions
__getattr__(name)
Get a metric result by field name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the field. |
required |
Returns:
| Type | Description |
|---|---|
FieldResult | ModelResult | ListResult
|
The FieldResult or ModelResult instance. |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the field does not exist. |
Source code in src/cobjectric/results.py
__getitem__(path)
Get a fill rate result by path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the field (e.g., "name", "address.city", "items[0].name"). |
required |
Returns:
| Type | Description |
|---|---|
FieldResult | ModelResult | ListResult
|
The FieldResult or ModelResult instance. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the path is invalid. |
Source code in src/cobjectric/results.py
__iter__()
__repr__()
Return a string representation of the FieldResultCollection.
ModelResult(_fields)
dataclass
Bases: StatsMixin
Result of metric computation for a model instance.
Attributes:
| Name | Type | Description |
|---|---|---|
_fields |
dict[str, FieldResult | ModelResult | ListResult]
|
Dictionary mapping field names to FieldResult, ModelResult, or ListResult instances. |
Attributes
fields
property
Get the FieldResultCollection for this result.
Returns:
| Type | Description |
|---|---|
FieldResultCollection
|
The FieldResultCollection containing all metric results. |
Functions
__add__(other)
Combine two ModelResults into a collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
'ModelResult'
|
Another ModelResult to combine. |
required |
Returns:
| Type | Description |
|---|---|
'ModelResultCollection'
|
ModelResultCollection containing both results. |
Raises:
| Type | Description |
|---|---|
IncompatibleModelResultError
|
If results come from different model types. |
Source code in src/cobjectric/results.py
__getitem__(path)
Get a fill rate result by path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the field (e.g., "name", "address.city", "items[0].name"). |
required |
Returns:
| Type | Description |
|---|---|
FieldResult | ModelResult | ListResult
|
The FieldResult or ModelResult instance. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the path is invalid. |
Source code in src/cobjectric/results.py
__repr__()
Return a string representation of the ModelResult.
to_series()
Export to pandas Series (requires cobjectric[pandas]).
Returns:
| Type | Description |
|---|---|
Any
|
pandas.Series with field paths as index and values as data. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If pandas is not installed. |
Source code in src/cobjectric/results.py
Similarity Results
See Similarity Guide for fuzzy matching and advanced strategies.
FieldResult(value, weight=1.0)
dataclass
Result of metric computation for a single field.
Attributes:
| Name | Type | Description |
|---|---|---|
value |
float
|
The metric value (float between 0.0 and 1.0). |
weight |
float
|
Weight for this field in weighted mean calculation (default: 1.0). |
FieldResultCollection(fields)
Collection of metric results for a model instance.
Provides attribute-based access to metric results.
Initialize a FieldResultCollection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
dict[str, FieldResult | ModelResult | ListResult]
|
Dictionary mapping field names to FieldResult, ModelResult, or ListResult instances. |
required |
Source code in src/cobjectric/results.py
Functions
__getattr__(name)
Get a metric result by field name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the field. |
required |
Returns:
| Type | Description |
|---|---|
FieldResult | ModelResult | ListResult
|
The FieldResult or ModelResult instance. |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the field does not exist. |
Source code in src/cobjectric/results.py
__getitem__(path)
Get a fill rate result by path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the field (e.g., "name", "address.city", "items[0].name"). |
required |
Returns:
| Type | Description |
|---|---|
FieldResult | ModelResult | ListResult
|
The FieldResult or ModelResult instance. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the path is invalid. |
Source code in src/cobjectric/results.py
__iter__()
__repr__()
Return a string representation of the FieldResultCollection.
ModelResult(_fields)
dataclass
Bases: StatsMixin
Result of metric computation for a model instance.
Attributes:
| Name | Type | Description |
|---|---|---|
_fields |
dict[str, FieldResult | ModelResult | ListResult]
|
Dictionary mapping field names to FieldResult, ModelResult, or ListResult instances. |
Attributes
fields
property
Get the FieldResultCollection for this result.
Returns:
| Type | Description |
|---|---|
FieldResultCollection
|
The FieldResultCollection containing all metric results. |
Functions
__add__(other)
Combine two ModelResults into a collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
'ModelResult'
|
Another ModelResult to combine. |
required |
Returns:
| Type | Description |
|---|---|
'ModelResultCollection'
|
ModelResultCollection containing both results. |
Raises:
| Type | Description |
|---|---|
IncompatibleModelResultError
|
If results come from different model types. |
Source code in src/cobjectric/results.py
__getitem__(path)
Get a fill rate result by path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the field (e.g., "name", "address.city", "items[0].name"). |
required |
Returns:
| Type | Description |
|---|---|
FieldResult | ModelResult | ListResult
|
The FieldResult or ModelResult instance. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the path is invalid. |
Source code in src/cobjectric/results.py
__repr__()
Return a string representation of the ModelResult.
to_series()
Export to pandas Series (requires cobjectric[pandas]).
Returns:
| Type | Description |
|---|---|
Any
|
pandas.Series with field paths as index and values as data. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If pandas is not installed. |
Source code in src/cobjectric/results.py
List Results
See List Comparison Strategies Guide for list handling and aggregation.
ListResult(_items, weight=1.0, _element_type=None)
dataclass
Bases: StatsMixin
Result for a list[BaseModel] field.
Provides two access modes: - By index: items[0] -> ModelResult - Aggregated (required): items.aggregated_fields.name -> AggregatedFieldResult
Attributes
aggregated_fields
property
Get aggregated fields collection for accessing fields across all items.
Returns:
| Type | Description |
|---|---|
AggregatedFieldResultCollection
|
AggregatedFieldResultCollection instance. |
value
property
Get the mean fill rate across all items.
Returns:
| Type | Description |
|---|---|
float
|
Mean fill rate. |
Functions
__getitem__(index)
Get fill rate result for a specific item by index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
The item index. |
required |
Returns:
| Type | Description |
|---|---|
ModelResult
|
ModelResult for the item. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If index is out of range. |
Source code in src/cobjectric/results.py
__iter__()
__len__()
AggregatedFieldResult(_values, _weights)
dataclass
Bases: StatsMixin
Aggregated fill rate result for a field across list items.
Provides statistical methods (mean, std, etc.) over all values of a specific field across multiple items in a list.
Attributes
values
property
Get all fill rate values for this field across items.
Returns:
| Type | Description |
|---|---|
list[float]
|
List of fill rate values. |
Functions
AggregatedFieldResultCollection(items)
Collection for aggregated field access on a list of fill rate results.
Provides access to aggregated field results across all items in the list.
Note
For nested lists (list[list[BaseModel]]), accessing a nested list field returns the mean fill rate of each list, not individual field access. Use indexed access to access nested list items individually.
Initialize the collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
list[ModelResult]
|
List of ModelResult instances. |
required |
Source code in src/cobjectric/results.py
Functions
__getattr__(name)
Get aggregated result for a field name across all items.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The field name. |
required |
Returns:
| Type | Description |
|---|---|
AggregatedFieldResult | AggregatedModelResult | NestedListAggregatedResult
|
AggregatedFieldResult, AggregatedModelResult, |
AggregatedFieldResult | AggregatedModelResult | NestedListAggregatedResult
|
or NestedListAggregatedResult. |
Raises:
| Type | Description |
|---|---|
InvalidAggregatedFieldError
|
If the field doesn't exist in the model. |
Source code in src/cobjectric/results.py
__repr__()
Return a string representation with available fields.
Source code in src/cobjectric/results.py
AggregatedModelResult(_items)
dataclass
Bases: StatsMixin
Aggregated result for a nested model field across list items.
Allows chained access: items.aggregated_fields.address.city
Note
For nested lists (list[list[BaseModel]]), accessing a nested list field returns the mean fill rate of each list, not individual field access. For example, if items have a tags field of type list[Tag], accessing items.aggregated_fields.tags returns a AggregatedFieldResult with the mean fill rate of each tags list, not access to individual tag fields.
Functions
__getattr__(name)
Get aggregated result for a field name across items.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The field name. |
required |
Returns:
| Type | Description |
|---|---|
AggregatedFieldResult | AggregatedModelResult | NestedListAggregatedResult
|
AggregatedFieldResult, AggregatedModelResult, |
AggregatedFieldResult | AggregatedModelResult | NestedListAggregatedResult
|
or NestedListAggregatedResult. |
Raises:
| Type | Description |
|---|---|
InvalidAggregatedFieldError
|
If the field doesn't exist in the model. |
Source code in src/cobjectric/results.py
NestedListAggregatedResult(lists, element_type=None)
Aggregated result for nested lists in fill rate results.
When accessing a list field through aggregated_fields, this allows chaining to further aggregate nested lists and access their fields.
Initialize NestedListAggregatedResult.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lists
|
list[ListResult]
|
List of ListResult instances. |
required |
element_type
|
type | None
|
The element type of the list (optional). |
None
|
Source code in src/cobjectric/results.py
Attributes
aggregated_fields
property
Get aggregated fields across all nested lists.
Flattens the nested lists and returns a collection for accessing fields across all items.
Returns:
| Type | Description |
|---|---|
AggregatedFieldResultCollection
|
AggregatedFieldResultCollection instance. |
values
property
Get fill rate values for nested lists.
By default, returns the mean fill rate of each list (one value per list). This is the hierarchical view. To get flattened values, use NestedListAggregatedResult.aggregated_fields to access individual items and their fields.
Returns:
| Type | Description |
|---|---|
list[float]
|
List of mean fill rates (one per list). |
Functions
__repr__()
max(hierarchical=False)
Get maximum fill rate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hierarchical
|
bool
|
If False (default), returns max of flattened values. If True, returns max of means for each list. |
False
|
Returns:
| Type | Description |
|---|---|
float
|
Maximum fill rate. |
Source code in src/cobjectric/results.py
mean(hierarchical=False)
Calculate mean fill rate across nested lists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hierarchical
|
bool
|
If False (default), flattens all values and calculates mean. If True, calculates mean of means for each list. |
False
|
Returns:
| Type | Description |
|---|---|
float
|
Mean fill rate. |
Source code in src/cobjectric/results.py
min(hierarchical=False)
Get minimum fill rate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hierarchical
|
bool
|
If False (default), returns min of flattened values. If True, returns min of means for each list. |
False
|
Returns:
| Type | Description |
|---|---|
float
|
Minimum fill rate. |
Source code in src/cobjectric/results.py
quantile(q, hierarchical=False)
Calculate quantile of fill rates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
float
|
The quantile to compute (float between 0.0 and 1.0). |
required |
hierarchical
|
bool
|
If False (default), calculates quantile of flattened values. If True, calculates quantile of means for each list. |
False
|
Returns:
| Type | Description |
|---|---|
float
|
The quantile value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If q is not in [0, 1]. |
Source code in src/cobjectric/results.py
std(hierarchical=False)
Calculate standard deviation across nested lists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hierarchical
|
bool
|
If False (default), calculates std of flattened values. If True, calculates std of means for each list. |
False
|
Returns:
| Type | Description |
|---|---|
float
|
Standard deviation. |
Source code in src/cobjectric/results.py
var(hierarchical=False)
Calculate variance across nested lists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hierarchical
|
bool
|
If False (default), calculates variance of flattened values. If True, calculates variance of means for each list. |
False
|
Returns:
| Type | Description |
|---|---|
float
|
Variance. |
Source code in src/cobjectric/results.py
Result Collections
See Pandas Export Guide for exporting results to pandas Series and DataFrames.
ModelResultCollection(results)
Collection of ModelResult for aggregated statistics.
Created by adding ModelResults together: result1 + result2 Provides methods to aggregate results and export to pandas DataFrame.
Initialize a ModelResultCollection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
list[ModelResult]
|
List of ModelResult instances (must be from same model type). |
required |
Source code in src/cobjectric/results.py
Functions
__add__(other)
Add a ModelResult or merge another collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
ModelResult | 'ModelResultCollection'
|
ModelResult or ModelResultCollection to add. |
required |
Returns:
| Type | Description |
|---|---|
'ModelResultCollection'
|
New ModelResultCollection with combined results. |
Raises:
| Type | Description |
|---|---|
IncompatibleModelResultError
|
If results come from different model types. |
Source code in src/cobjectric/results.py
__len__()
__repr__()
max()
Get maximum value for each field across all results.
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Dictionary mapping field paths to maximum values. |
Source code in src/cobjectric/results.py
mean()
Calculate mean value for each field across all results.
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Dictionary mapping field paths to mean values. |
Source code in src/cobjectric/results.py
min()
Get minimum value for each field across all results.
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Dictionary mapping field paths to minimum values. |
Source code in src/cobjectric/results.py
quantile(q)
Calculate quantile for each field across all results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
float
|
The quantile to compute (float between 0.0 and 1.0). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Dictionary mapping field paths to quantile values. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If q is not in [0, 1]. |
Source code in src/cobjectric/results.py
std()
Calculate standard deviation for each field across all results.
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Dictionary mapping field paths to standard deviation values. |
Source code in src/cobjectric/results.py
to_dataframe()
Export to pandas DataFrame (requires cobjectric[pandas]).
Each row represents one ModelResult, columns are field paths.
Returns:
| Type | Description |
|---|---|
Any
|
pandas.DataFrame with one row per ModelResult. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If pandas is not installed. |
Source code in src/cobjectric/results.py
var()
Calculate variance for each field across all results.
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Dictionary mapping field paths to variance values. |
Source code in src/cobjectric/results.py
Decorator Info Classes
FillRateFuncInfo(field_patterns, func, weight=1.0)
dataclass
Stores fill_rate_func info attached to a method.
Attributes:
| Name | Type | Description |
|---|---|---|
field_patterns |
tuple[str, ...]
|
Tuple of field names or glob patterns to match. |
func |
FillRateFunc
|
The fill_rate_func to apply. |
weight |
float
|
Weight for fill rate computation (default: 1.0, must be >= 0.0). |
FillRateAccuracyFuncInfo(field_patterns, func, weight=1.0)
dataclass
Stores fill_rate_accuracy_func info attached to a method.
Attributes:
| Name | Type | Description |
|---|---|---|
field_patterns |
tuple[str, ...]
|
Tuple of field names or glob patterns to match. |
func |
FillRateAccuracyFunc
|
The fill_rate_accuracy_func to apply. |
weight |
float
|
Weight for fill rate accuracy computation (default: 1.0, must be >= 0.0). |
SimilarityFuncInfo(field_patterns, func, weight=1.0)
dataclass
Stores similarity_func info attached to a method.
Attributes:
| Name | Type | Description |
|---|---|---|
field_patterns |
tuple[str, ...]
|
Tuple of field names or glob patterns to match. |
func |
SimilarityFunc
|
The similarity_func to apply. |
weight |
float
|
Weight for similarity computation (default: 1.0, must be >= 0.0). |
List Comparison Strategies
ListCompareStrategy
Bases: str, Enum
Strategy for comparing list[BaseModel] items.
Attributes:
| Name | Type | Description |
|---|---|---|
PAIRWISE |
Compare items by their index (default). |
|
LEVENSHTEIN |
Align items based on Levenshtein distance + similarity. |
|
OPTIMAL_ASSIGNMENT |
Find optimal one-to-one mapping using Hungarian algorithm. |
Similarity Functions
See Similarity Guide for implementation details and best practices.
exact_similarity(a, b)
Exact equality similarity.
Returns 1.0 if a == b, else 0.0. Works with any type (str, int, float, bool, etc.)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
Any
|
First value to compare. |
required |
b
|
Any
|
Second value to compare. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
1.0 if values are equal, 0.0 otherwise. |
Examples:
>>> exact_similarity("John", "John")
1.0
>>> exact_similarity("John", "Jane")
0.0
>>> exact_similarity(10, 10)
1.0
>>> exact_similarity(10, 11)
0.0
Source code in src/cobjectric/similarity.py
fuzzy_similarity_factory(scorer='ratio')
Factory to create fuzzy string similarity using rapidfuzz.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scorer
|
str
|
The rapidfuzz.fuzz scorer to use. Options: - "ratio" (default): Standard Levenshtein ratio - "partial_ratio": Best partial match ratio - "token_sort_ratio": Token sorted ratio - "token_set_ratio": Token set ratio - "WRatio": Weighted ratio (smart combination) - "QRatio": Quick ratio |
'ratio'
|
Returns:
| Type | Description |
|---|---|
SimilarityFunc
|
A similarity function that compares two string values. |
Examples:
>>> fuzzy = fuzzy_similarity_factory()
>>> fuzzy("John Doe", "John Doe")
1.0
>>> fuzzy("John Doe", "john doe") # case difference
0.9...
>>> fuzzy("John Doe", "Jane Doe")
0.75...
Source code in src/cobjectric/similarity.py
numeric_similarity_factory(max_difference=None)
Factory for numeric similarity based on difference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_difference
|
float | None
|
Maximum absolute difference for comparison. - None (default): Exact match only (1.0 if a == b, 0.0 otherwise) - float > 0: Gradual similarity based on difference Formula: max(0.0, 1.0 - |a - b| / max_difference) |
None
|
Returns:
| Type | Description |
|---|---|
SimilarityFunc
|
A similarity function that compares two numeric values. |
Examples:
>>> # Exact match required
>>> exact = numeric_similarity_factory()
>>> exact(10, 10)
1.0
>>> exact(10, 11)
0.0
>>>
>>> # Gradual decrease: up to 5 units of difference
>>> gradual = numeric_similarity_factory(max_difference=5.0)
>>> gradual(10, 10)
1.0
>>> gradual(10, 12) # diff=2, 2/5=0.4, 1-0.4=0.6
0.6
>>> gradual(10, 15) # diff=5, 5/5=1.0, 1-1.0=0.0
0.0
>>> gradual(10, 20) # diff>max, capped at 0
0.0
Raises:
| Type | Description |
|---|---|
ValueError
|
If max_difference is <= 0. |
Source code in src/cobjectric/similarity.py
datetime_similarity_factory(max_difference=None)
Factory for datetime similarity based on time difference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_difference
|
timedelta | None
|
Maximum time difference as timedelta for comparison. - None (default): Exact match only (1.0 if a == b, 0.0 otherwise) - timedelta > 0: Gradual similarity based on time difference Formula: max(0.0, 1.0 - |time_diff| / max_difference) |
None
|
Returns:
| Type | Description |
|---|---|
SimilarityFunc
|
A similarity function that compares two datetime string values (ISO format). |
Examples:
>>> from datetime import timedelta
>>> # Exact match required
>>> exact = datetime_similarity_factory()
>>> exact("2024-01-15T10:30:00Z", "2024-01-15T10:30:00Z")
1.0
>>> exact("2024-01-15T10:30:00Z", "2024-01-15T10:30:01Z")
0.0
>>>
>>> # Gradual decrease: up to 1 hour of difference
>>> gradual = datetime_similarity_factory(max_difference=timedelta(hours=1))
>>> gradual("2024-01-15T10:00:00Z", "2024-01-15T10:00:00Z")
1.0
>>> gradual("2024-01-15T10:00:00Z", "2024-01-15T10:30:00Z") # 30 min
... # diff=30min, 30min/60min=0.5, 1-0.5=0.5
0.5
>>> gradual("2024-01-15T10:00:00Z", "2024-01-15T11:00:00Z") # 1 hour
... # diff=1h, 1h/1h=1.0, 1-1.0=0.0
0.0
Raises:
| Type | Description |
|---|---|
ValueError
|
If max_difference is <= 0. |
Source code in src/cobjectric/similarity.py
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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
Pre-defined Specs
See Pre-defined Specs Guide for detailed usage and recommendations.
KeywordSpec
KeywordSpec(strip=True, convert_int_to_str=True, metadata=None, fill_rate_func=None, fill_rate_weight=1.0, fill_rate_accuracy_func=None, fill_rate_accuracy_weight=1.0, similarity_func=None, similarity_weight=1.0, list_compare_strategy=None)
Pre-defined Spec for keyword/identifier fields (exact matching).
Optimized for identifiers, codes, enums, etc. Uses exact similarity and optional string stripping and int-to-string conversion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strip
|
bool
|
If True (default), strip leading/trailing whitespace. |
True
|
convert_int_to_str
|
bool
|
If True (default), convert int values to string. Useful when IDs come as integers from JSON but should be compared as strings. |
True
|
metadata
|
dict[str, Any] | None
|
Optional metadata for the field. |
None
|
fill_rate_func
|
Any
|
Optional fill rate function. |
None
|
fill_rate_weight
|
float
|
Weight for fill rate computation (default: 1.0). |
1.0
|
fill_rate_accuracy_func
|
Any
|
Optional fill rate accuracy function. |
None
|
fill_rate_accuracy_weight
|
float
|
Weight for fill rate accuracy (default: 1.0). |
1.0
|
similarity_func
|
Any
|
Optional similarity function (default: exact_similarity). |
None
|
similarity_weight
|
float
|
Weight for similarity computation (default: 1.0). |
1.0
|
list_compare_strategy
|
Any
|
Strategy for comparing list[BaseModel] items. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
FieldSpec instance optimized for keyword fields. |
Source code in src/cobjectric/specs.py
TextSpec
TextSpec(lower=True, strip=True, collapse_spaces=True, remove_accents=True, scorer='WRatio', metadata=None, fill_rate_func=None, fill_rate_weight=1.0, fill_rate_accuracy_func=None, fill_rate_accuracy_weight=1.0, similarity_func=None, similarity_weight=1.0, list_compare_strategy=None)
Pre-defined Spec for text fields (fuzzy matching).
Optimized for free-form text. Uses fuzzy similarity and comprehensive text normalization (lowercase, strip, collapse spaces, remove accents).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lower
|
bool
|
If True (default), convert to lowercase. |
True
|
strip
|
bool
|
If True (default), strip leading/trailing whitespace. |
True
|
collapse_spaces
|
bool
|
If True (default), collapse multiple spaces to single. |
True
|
remove_accents
|
bool
|
If True (default), remove accents from characters. |
True
|
scorer
|
str
|
The rapidfuzz scorer to use (default: "WRatio"). |
'WRatio'
|
metadata
|
dict[str, Any] | None
|
Optional metadata for the field. |
None
|
fill_rate_func
|
Any
|
Optional fill rate function. |
None
|
fill_rate_weight
|
float
|
Weight for fill rate computation (default: 1.0). |
1.0
|
fill_rate_accuracy_func
|
Any
|
Optional fill rate accuracy function. |
None
|
fill_rate_accuracy_weight
|
float
|
Weight for fill rate accuracy (default: 1.0). |
1.0
|
similarity_func
|
Any
|
Optional similarity function (default: fuzzy). |
None
|
similarity_weight
|
float
|
Weight for similarity computation (default: 1.0). |
1.0
|
list_compare_strategy
|
Any
|
Strategy for comparing list[BaseModel] items. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
FieldSpec instance optimized for text fields. |
Source code in src/cobjectric/specs.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
NumericSpec
NumericSpec(max_difference=None, coerce_type=True, metadata=None, fill_rate_func=None, fill_rate_weight=1.0, fill_rate_accuracy_func=None, fill_rate_accuracy_weight=1.0, similarity_func=None, similarity_weight=1.0, list_compare_strategy=None)
Pre-defined Spec for numeric fields.
Optimized for numbers (int, float). Uses numeric similarity with optional tolerance. Can coerce JSON Number to int/float based on field type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_difference
|
float | None
|
Maximum difference for similarity (None = exact match). |
None
|
coerce_type
|
bool
|
If True (default), coerce to int/float based on field type. Handles JSON Number -> Python int/float conversion. |
True
|
metadata
|
dict[str, Any] | None
|
Optional metadata for the field. |
None
|
fill_rate_func
|
Any
|
Optional fill rate function. |
None
|
fill_rate_weight
|
float
|
Weight for fill rate computation (default: 1.0). |
1.0
|
fill_rate_accuracy_func
|
Any
|
Optional fill rate accuracy function. |
None
|
fill_rate_accuracy_weight
|
float
|
Weight for fill rate accuracy (default: 1.0). |
1.0
|
similarity_func
|
Any
|
Optional similarity function (default: numeric). |
None
|
similarity_weight
|
float
|
Weight for similarity computation (default: 1.0). |
1.0
|
list_compare_strategy
|
Any
|
Strategy for comparing list[BaseModel] items. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
FieldSpec instance optimized for numeric fields. |
Example
Source code in src/cobjectric/specs.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
BooleanSpec
BooleanSpec(metadata=None, fill_rate_func=None, fill_rate_weight=1.0, fill_rate_accuracy_func=None, fill_rate_accuracy_weight=1.0, similarity_func=None, similarity_weight=1.0, list_compare_strategy=None)
Pre-defined Spec for boolean fields.
Optimized for boolean values. Uses exact similarity and converts various values to bool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
dict[str, Any] | None
|
Optional metadata for the field. |
None
|
fill_rate_func
|
Any
|
Optional fill rate function. |
None
|
fill_rate_weight
|
float
|
Weight for fill rate computation (default: 1.0). |
1.0
|
fill_rate_accuracy_func
|
Any
|
Optional fill rate accuracy function. |
None
|
fill_rate_accuracy_weight
|
float
|
Weight for fill rate accuracy (default: 1.0). |
1.0
|
similarity_func
|
Any
|
Optional similarity function (default: exact_similarity). |
None
|
similarity_weight
|
float
|
Weight for similarity computation (default: 1.0). |
1.0
|
list_compare_strategy
|
Any
|
Strategy for comparing list[BaseModel] items. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
FieldSpec instance optimized for boolean fields. |
Source code in src/cobjectric/specs.py
DatetimeSpec
DatetimeSpec(format=None, max_difference=None, metadata=None, fill_rate_func=None, fill_rate_weight=1.0, fill_rate_accuracy_func=None, fill_rate_accuracy_weight=1.0, similarity_func=None, similarity_weight=1.0, list_compare_strategy=None)
Pre-defined Spec for datetime fields.
Optimized for datetime strings (ISO format). Uses datetime similarity with optional time difference tolerance. Normalizes all datetime values to ISO format strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
format
|
str | None
|
Optional datetime format string for parsing (auto-detect if None). If specified, uses datetime.strptime() with this format. Example: "%Y-%m-%d %H:%M:%S", "%d/%m/%Y", etc. |
None
|
max_difference
|
timedelta | None
|
Maximum time difference as timedelta (None = exact). Use timedelta(days=1), timedelta(hours=1), timedelta(minutes=30), etc. |
None
|
metadata
|
dict[str, Any] | None
|
Optional metadata for the field. |
None
|
fill_rate_func
|
Any
|
Optional fill rate function. |
None
|
fill_rate_weight
|
float
|
Weight for fill rate computation (default: 1.0). |
1.0
|
fill_rate_accuracy_func
|
Any
|
Optional fill rate accuracy function. |
None
|
fill_rate_accuracy_weight
|
float
|
Weight for fill rate accuracy (default: 1.0). |
1.0
|
similarity_func
|
Any
|
Optional similarity function (default: datetime). |
None
|
similarity_weight
|
float
|
Weight for similarity computation (default: 1.0). |
1.0
|
list_compare_strategy
|
Any
|
Strategy for comparing list[BaseModel] items. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
FieldSpec instance optimized for datetime fields. |
Example
Source code in src/cobjectric/specs.py
Default Functions
Fill Rate Functions
not_missing_fill_rate(value)
Fill rate function: returns 0.0 if MissingValue, else 1.0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
The field value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
0.0 if MissingValue, 1.0 otherwise. |
Examples:
>>> from cobjectric.fill_rate import not_missing_fill_rate
>>> from cobjectric import MissingValue
>>> not_missing_fill_rate("John")
1.0
>>> not_missing_fill_rate(MissingValue)
0.0
Source code in src/cobjectric/fill_rate.py
Fill Rate Accuracy Functions
same_state_fill_rate_accuracy(got, expected)
Fill rate accuracy function: returns 1.0 if both have same state, else 0.0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
got
|
Any
|
The field value from the model being evaluated. |
required |
expected
|
Any
|
The field value from the expected model. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
1.0 if both are filled or both are MissingValue, 0.0 otherwise. |
Examples:
>>> from cobjectric.fill_rate_accuracy import same_state_fill_rate_accuracy
>>> from cobjectric import MissingValue
>>> same_state_fill_rate_accuracy("John", "Jane")
1.0
>>> same_state_fill_rate_accuracy("John", MissingValue)
0.0
>>> same_state_fill_rate_accuracy(MissingValue, MissingValue)
1.0
Source code in src/cobjectric/fill_rate_accuracy.py
Decorator Functions
fill_rate_func(*field_patterns, weight=1.0)
Decorator to define a fill_rate_func for one or more fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*field_patterns
|
str
|
Field names or glob patterns (e.g., "name", "email", "name_*") |
()
|
weight
|
float
|
Weight for fill rate computation (default: 1.0, must be >= 0.0). |
1.0
|
Returns:
| Type | Description |
|---|---|
Callable[[FillRateFunc], FillRateFunc]
|
Decorated function |
Raises:
| Type | Description |
|---|---|
InvalidWeightError
|
If weight is negative (< 0.0). |
Example
Source code in src/cobjectric/fill_rate.py
fill_rate_accuracy_func(*field_patterns, weight=1.0)
Decorator to define a fill_rate_accuracy_func for one or more fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*field_patterns
|
str
|
Field names or glob patterns (e.g., "name", "email", "name_*") |
()
|
weight
|
float
|
Weight for fill rate accuracy computation (default: 1.0, must be >= 0.0). |
1.0
|
Returns:
| Type | Description |
|---|---|
Callable[[FillRateAccuracyFunc], FillRateAccuracyFunc]
|
Decorated function |
Raises:
| Type | Description |
|---|---|
InvalidWeightError
|
If weight is negative (< 0.0). |
Example
Source code in src/cobjectric/fill_rate_accuracy.py
similarity_func(*field_patterns, weight=1.0)
Decorator to define a similarity_func for one or more fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*field_patterns
|
str
|
Field names or glob patterns (e.g., "name", "email", "name_*") |
()
|
weight
|
float
|
Weight for similarity computation (default: 1.0, must be >= 0.0). |
1.0
|
Returns:
| Type | Description |
|---|---|
Callable[[SimilarityFunc], SimilarityFunc]
|
Decorated function |
Raises:
| Type | Description |
|---|---|
InvalidWeightError
|
If weight is negative (< 0.0). |
Example
Source code in src/cobjectric/similarity.py
field_normalizer(*field_patterns)
Decorator to define a normalizer for one or more fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*field_patterns
|
str
|
Field names or glob patterns (e.g., "name", "email", "name_*") |
()
|
Returns:
| Type | Description |
|---|---|
Callable[[Callable[..., Any]], Callable[..., Any]]
|
Decorated function |
Source code in src/cobjectric/normalizer.py
Exceptions
All exceptions inherit from CobjectricError. Handle them appropriately in your error handling logic.
Base Exception
CobjectricError
Bases: Exception
Base exception for all cobjectric errors.
Type Exceptions
UnsupportedTypeError(unsupported_type)
Bases: CobjectricError
Exception raised when a field type is not supported.
This exception is raised when a field type is not JSON-compatible. Only str, int, float, bool, list[T], or BaseModel subclasses are allowed.
Initialize UnsupportedTypeError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unsupported_type
|
type
|
The unsupported type that was detected. |
required |
Source code in src/cobjectric/exceptions.py
Functions
UnsupportedListTypeError(unsupported_type)
Bases: CobjectricError
Exception raised when a list field has an unsupported type.
This exception is raised when a list field contains a Union type, which is not supported. Only single types are allowed in lists.
Initialize UnsupportedListTypeError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unsupported_type
|
type
|
The unsupported type that was detected. |
required |
Source code in src/cobjectric/exceptions.py
Functions
MissingListTypeArgError()
Bases: CobjectricError
Exception raised when a list type is used without type arguments.
This exception is raised when using bare 'list' or 't.List' without specifying the element type.
Initialize MissingListTypeArgError.
Source code in src/cobjectric/exceptions.py
Functions
Function Definition Exceptions
DuplicateFillRateFuncError(field_name)
Bases: CobjectricError
Exception raised when multiple fill_rate_func are defined for the same field.
This exception is raised when a field has both a Spec(fill_rate_func=...) and a @fill_rate_func decorator, or multiple @fill_rate_func decorators.
Initialize DuplicateFillRateFuncError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_name
|
str
|
The name of the field with duplicate fill_rate_func. |
required |
Source code in src/cobjectric/exceptions.py
Functions
DuplicateFillRateAccuracyFuncError(field_name)
Bases: CobjectricError
Exception raised when multiple fill_rate_accuracy_func are defined.
This exception is raised when a field has both a Spec(fill_rate_accuracy_func=...) and a @fill_rate_accuracy_func decorator, or multiple @fill_rate_accuracy_func decorators.
Initialize DuplicateFillRateAccuracyFuncError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_name
|
str
|
The name of the field with duplicate fill_rate_accuracy_func. |
required |
Source code in src/cobjectric/exceptions.py
Functions
DuplicateSimilarityFuncError(field_name)
Bases: CobjectricError
Exception raised when multiple similarity_func are defined.
This exception is raised when a field has both a Spec(similarity_func=...) and a @similarity_func decorator, or multiple @similarity_func decorators.
Initialize DuplicateSimilarityFuncError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_name
|
str
|
The name of the field with duplicate similarity_func. |
required |
Source code in src/cobjectric/exceptions.py
Functions
Validation Exceptions
InvalidFillRateValueError(field_name, value)
Bases: CobjectricError
Exception raised when fill_rate_func returns an invalid value.
This exception is raised when fill_rate_func returns a value that is not a float (or int convertible to float) or is not in the range [0, 1].
Initialize InvalidFillRateValueError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_name
|
str
|
The name of the field with invalid fill_rate value. |
required |
value
|
Any
|
The invalid value that was returned. |
required |
Source code in src/cobjectric/exceptions.py
Functions
InvalidWeightError(weight, source, weight_type='fill_rate')
Bases: CobjectricError
Exception raised when weight is invalid.
This exception is raised when weight is negative (< 0.0). Weight must be >= 0.0.
Initialize InvalidWeightError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weight
|
float
|
The invalid weight value. |
required |
source
|
str
|
The source of the weight ("Spec" or "decorator"). |
required |
weight_type
|
str
|
The type of weight ("fill_rate" or "fill_rate_accuracy"). |
'fill_rate'
|
Source code in src/cobjectric/exceptions.py
Functions
InvalidAggregatedFieldError(field_name, available_fields, model_type=None)
Bases: CobjectricError
Exception raised when accessing an invalid field in aggregated_fields.
This exception is raised when trying to access a field that doesn't exist in the aggregated model through aggregated_fields property.
Initialize InvalidAggregatedFieldError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_name
|
str
|
The name of the field that was accessed. |
required |
available_fields
|
list[str]
|
List of available field names. |
required |
model_type
|
type | None
|
The model type (optional) for additional context. |
None
|
Source code in src/cobjectric/exceptions.py
Functions
InvalidListCompareStrategyError(field_name)
Bases: CobjectricError
Exception raised when list_compare_strategy is used on a non-list field.
This exception is raised when trying to use list_compare_strategy on a field that is not a list[BaseModel] type.
Initialize InvalidListCompareStrategyError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_name
|
str
|
The name of the field with invalid list_compare_strategy. |
required |