You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class Binning(Model):
nodetype: Literal["binning"]
input: str
edges: List[float]
"Edges of the binning, where edges[i] <= x < edges[i+1] => f(x, ...) = content[i](...)"
content: List[Content]
@validator('edges')
def validate_edges(cls,edges,values):
for i, lowedge in enumerate(edges[:-1]):
if lowedge>=edges[i+1]:
raise ValueError("bin edges not in increasing order: %s"%(edges))
return edges
@validator('content')
def match_content_bins(cls,content,values):
if 'edges' in values:
nbins = len(values['edges'])-1
if len(content)!=nbins:
raise ValueError("number of content elements (%s) must match number of bins (%s)"%(len(content),nbins))
return content
or one could override __init__.
More examples are here. (pydantic errors are quite verbose, so I added some highlighting.)
The text was updated successfully, but these errors were encountered:
The current
pydantic
Models are useful to create valid JSON files. One could add some more basic checks during generation, like checking#(edges-1)==#(content)
for 1D binning, and similar for multibinning;#(keys)==#(content)
for categories;#(axis)==#(input parameters)
for multibinning (see issue Associate Content with input variable #2);pydantic
provides validator methods, e.g.or one could override
__init__
.More examples are here. (
pydantic
errors are quite verbose, so I added some highlighting.)The text was updated successfully, but these errors were encountered: