File tree Expand file tree Collapse file tree 3 files changed +27
-4
lines changed Expand file tree Collapse file tree 3 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -27,15 +27,16 @@ def _node_title_generator(node: Type[Node]) -> str:
2727
2828class Node (
2929 pydantic .BaseModel ,
30+ allow_inf_nan = False ,
3031 extra = "forbid" ,
3132 frozen = False ,
33+ model_title_generator = _node_title_generator ,
3234 populate_by_name = True ,
3335 revalidate_instances = "never" ,
36+ use_attribute_docstrings = True ,
3437 validate_assignment = True ,
3538 validate_default = False ,
3639 validate_return = True , # TODO: check if False here would bring a speedup and can still be safe
37- use_attribute_docstrings = True ,
38- model_title_generator = _node_title_generator ,
3940):
4041 """""" # empty docstring to remove all pydantic docstrings from the pdoc spec docs
4142
Original file line number Diff line number Diff line change 7676)
7777from .._internal .io_utils import load_array
7878from .._internal .node_converter import Converter
79+ from .._internal .type_guards import is_dict , is_sequence
7980from .._internal .types import (
8081 AbsoluteTolerance ,
8182 LowerCaseIdentifier ,
@@ -878,6 +879,27 @@ class IntervalOrRatioDataDescr(Node):
878879 offset : Optional [float ] = None
879880 """Offset for data on a ratio scale."""
880881
882+ @model_validator (mode = "before" )
883+ def _replace_inf (cls , data : Any ):
884+ if is_dict (data ):
885+ if "range" in data and is_sequence (data ["range" ]):
886+ forbidden = (
887+ "inf" ,
888+ "-inf" ,
889+ ".inf" ,
890+ "-.inf" ,
891+ float ("inf" ),
892+ float ("-inf" ),
893+ )
894+ if any (v in forbidden for v in data ["range" ]):
895+ issue_warning ("replaced 'inf' value" , value = data ["range" ])
896+
897+ data ["range" ] = tuple (
898+ (None if v in forbidden else v ) for v in data ["range" ]
899+ )
900+
901+ return data
902+
881903
882904TensorDataDescr = Union [NominalOrOrdinalDataDescr , IntervalOrRatioDataDescr ]
883905
Original file line number Diff line number Diff line change @@ -129,7 +129,7 @@ def test_tensor_base_invalid(kwargs: Dict[str, Any]):
129129 {
130130 "id" : "input_1" ,
131131 "description" : "Input 1" ,
132- "data" : {"type" : "float32" },
132+ "data" : {"type" : "float32" , "range" : [ "-inf" , float ( "inf" )] },
133133 "axes" : [
134134 dict (type = "space" , id = "x" , size = 10 ),
135135 dict (type = "space" , id = "y" , size = 11 ),
@@ -146,7 +146,7 @@ def test_tensor_base_invalid(kwargs: Dict[str, Any]):
146146 }
147147 ],
148148 "test_tensor" : {"source" : UNET2D_ROOT / "test_input.npy" },
149- },
149+ }
150150 ],
151151)
152152def test_input_tensor (kwargs : Dict [str , Any ]):
You can’t perform that action at this time.
0 commit comments