Skip to content

Commit 23da78f

Browse files
Nush395Torax team
authored andcommitted
Backwards compatibility fix.
Old config files are saved with the `nx` field which upon reloading now throws an error. Add a before validator so that old file inputs are sanitised before construction. PiperOrigin-RevId: 861228611
1 parent ff9010c commit 23da78f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

torax/_src/torax_pydantic/interpolated_param_2d.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ class Grid1D(model_base.BaseModelFrozen):
5151
"""
5252
face_centers: pydantic_types.NumpyArray1DSorted
5353

54+
@pydantic.model_validator(mode='before')
55+
@classmethod
56+
def _conform_data(cls, data: Any) -> Any:
57+
if not isinstance(data, dict):
58+
return data
59+
if 'nx' in data:
60+
nx = data['nx']
61+
face_centers = get_face_centers(nx)
62+
data['face_centers'] = face_centers
63+
del data['nx']
64+
return data
65+
5466
@pydantic.field_validator('face_centers')
5567
@classmethod
5668
def _validate_face_centers(cls, v: np.ndarray) -> np.ndarray:

0 commit comments

Comments
 (0)