22
33This module provides frozen dataclasses for defining model specifications
44in a type-safe, immutable manner. All collections use immutable types
5- (tuples, frozendict) to ensure the specification cannot be accidentally modified.
5+ (tuples, MappingProxyType) to ensure the specification cannot be accidentally
6+ modified.
67"""
78
89from collections .abc import Callable
910from dataclasses import dataclass , field
1011from types import MappingProxyType
1112from typing import Self
1213
13- from frozendict import frozendict
14-
1514
1615@dataclass (frozen = True )
1716class Normalizations :
@@ -25,15 +24,15 @@ class Normalizations:
2524
2625 """
2726
28- loadings : tuple [frozendict [str , float ], ...]
29- intercepts : tuple [frozendict [str , float ], ...]
27+ loadings : tuple [MappingProxyType [str , float ], ...]
28+ intercepts : tuple [MappingProxyType [str , float ], ...]
3029
3130 @classmethod
3231 def from_dict (cls , d : dict ) -> Self :
3332 """Create Normalizations from a dictionary specification."""
3433 return cls (
35- loadings = tuple (frozendict (x ) for x in d ["loadings" ]),
36- intercepts = tuple (frozendict (x ) for x in d ["intercepts" ]),
34+ loadings = tuple (MappingProxyType (x ) for x in d ["loadings" ]),
35+ intercepts = tuple (MappingProxyType (x ) for x in d ["intercepts" ]),
3736 )
3837
3938 def to_dict (self ) -> dict :
@@ -169,8 +168,8 @@ def to_dict(self) -> dict:
169168 return result
170169
171170
172- def _default_empty_frozendict () -> frozendict [str , str ]:
173- return frozendict ({})
171+ def _default_empty_mapping_proxy () -> MappingProxyType [str , str ]:
172+ return MappingProxyType ({})
174173
175174
176175@dataclass (frozen = True )
@@ -186,7 +185,9 @@ class AnchoringSpec:
186185
187186 """
188187
189- outcomes : frozendict [str , str ] = field (default_factory = _default_empty_frozendict )
188+ outcomes : MappingProxyType [str , str ] = field (
189+ default_factory = _default_empty_mapping_proxy ,
190+ )
190191 free_controls : bool = False
191192 free_constant : bool = False
192193 free_loadings : bool = False
@@ -198,7 +199,7 @@ def from_dict(cls, d: dict) -> Self:
198199 outcomes = d .get ("outcomes" , {})
199200 ignore_constant = d .get ("ignore_constant_when_anchoring" , False )
200201 return cls (
201- outcomes = frozendict (outcomes ),
202+ outcomes = MappingProxyType (outcomes ),
202203 free_controls = d .get ("free_controls" , False ),
203204 free_constant = d .get ("free_constant" , False ),
204205 free_loadings = d .get ("free_loadings" , False ),
0 commit comments