VariableSchema#
- class pymc_marketing.data.idata.schema.VariableSchema(*, name, required=True, dims, dtype=None, description='')[source]#
Schema for a single variable in DataTree group.
Validates the structure (dimensions and dtype) of xarray.DataArray variables within DataTree groups.
- Parameters:
name (
str) – Variable namerequired (
bool) – Whether this variable must be presentdims (
Union[tuple[str,...],Literal['*']]) – Expected dimension names. Use “*” to accept any dimensions.dtype (
str|tuple[str,...] |None) – Expected numpy dtype(s) (e.g., “float64”, “int64”, or (“float64”, “int64”)). Use None to skip dtype validation.description (
str) – Human-readable description of this variable
Examples
>>> schema = VariableSchema( ... name="channel_contribution", ... dims=("date", "channel"), ... dtype="float64", ... required=True, ... ) >>> data_array = xr.DataArray(...) >>> errors = schema.validate_variable(data_array) >>> if errors: ... print("Validation errors:", errors)
Methods
VariableSchema.__init__(**data)Create a new model by parsing and validating input data from keyword arguments.
VariableSchema.construct([_fields_set])VariableSchema.copy(*[, include, exclude, ...])Returns a copy of the model.
VariableSchema.dict(*[, include, exclude, ...])VariableSchema.json(*[, include, exclude, ...])Compute the class name for parametrizations of generic classes.
VariableSchema.parse_file(path, *[, ...])VariableSchema.parse_raw(b, *[, ...])VariableSchema.schema([by_alias, ref_template])VariableSchema.schema_json(*[, by_alias, ...])VariableSchema.update_forward_refs(**localns)VariableSchema.validate(value)VariableSchema.validate_variable(data_array)Validate variable structure.
Attributes
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].