From 47a535b63ac869bbb3a507a17812c8e6b24971f5 Mon Sep 17 00:00:00 2001 From: hdoupe Date: Sat, 1 Mar 2025 08:45:52 -0500 Subject: [PATCH 1/2] Fields.Field -> Fields.Raw --- paramtools/schema.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/paramtools/schema.py b/paramtools/schema.py index ebbb453..bc1d3f9 100644 --- a/paramtools/schema.py +++ b/paramtools/schema.py @@ -28,14 +28,14 @@ class RangeSchema(Schema): } """ - _min = fields.Field(attribute="min", data_key="min") - _max = fields.Field(attribute="max", data_key="max") - step = fields.Field() + _min = fields.Raw(attribute="min", data_key="min") + _max = fields.Raw(attribute="max", data_key="max") + step = fields.Raw() level = fields.String(validate=[validate.OneOf(["warn", "error"])]) class ChoiceSchema(Schema): - choices = fields.List(fields.Field) + choices = fields.List(fields.Raw) level = fields.String(validate=[validate.OneOf(["warn", "error"])]) @@ -53,9 +53,9 @@ class ValueValidatorSchema(Schema): class IsSchema(Schema): - equal_to = fields.Field(required=False) - greater_than = fields.Field(required=False) - less_than = fields.Field(required=False) + equal_to = fields.Raw(required=False) + greater_than = fields.Raw(required=False) + less_than = fields.Raw(required=False) @validates_schema def just_one(self, data, **kwargs): @@ -107,7 +107,7 @@ class BaseParamSchema(Schema): data_key="type", ) number_dims = fields.Integer(required=False, load_default=0) - value = fields.Field(required=True) # will be specified later + value = fields.Raw(required=True) # will be specified later validators = fields.Nested( ValueValidatorSchema(), required=False, load_default={} ) From aecfda00a70983c40e0c390642f5764855c35ff9 Mon Sep 17 00:00:00 2001 From: hdoupe Date: Sat, 1 Mar 2025 08:57:09 -0500 Subject: [PATCH 2/2] Dicts ordered by default now --- paramtools/schema.py | 15 --------------- paramtools/schema_factory.py | 9 +++------ paramtools/tests/test_parameters.py | 13 +++---------- 3 files changed, 6 insertions(+), 31 deletions(-) diff --git a/paramtools/schema.py b/paramtools/schema.py index bc1d3f9..820cf36 100644 --- a/paramtools/schema.py +++ b/paramtools/schema.py @@ -113,9 +113,6 @@ class BaseParamSchema(Schema): ) indexed = fields.Boolean(required=False) - class Meta: - ordered = True - class EmptySchema(Schema): """ @@ -126,15 +123,6 @@ class EmptySchema(Schema): pass -class OrderedSchema(Schema): - """ - Same as `EmptySchema`, but preserves the order of its fields. - """ - - class Meta: - ordered = True - - class ValueObject(fields.Nested): """ Schema for value objects @@ -182,9 +170,6 @@ class BaseValidatorSchema(Schema): class. """ - class Meta: - ordered = True - WRAPPER_MAP = { "range": "_get_range_validator", "date_range": "_get_range_validator", diff --git a/paramtools/schema_factory.py b/paramtools/schema_factory.py index b841169..dc61dbb 100644 --- a/paramtools/schema_factory.py +++ b/paramtools/schema_factory.py @@ -1,7 +1,6 @@ -from marshmallow import fields +from marshmallow import fields, Schema from paramtools.schema import ( - OrderedSchema, BaseValidatorSchema, ValueObject, get_type, @@ -67,9 +66,7 @@ def schemas(self): # if not isinstance(v["value"], list): # v["value"] = [{"value": v["value"]}] - validator_dict[k] = type( - "ValidatorItem", (OrderedSchema,), classattrs - ) + validator_dict[k] = type("ValidatorItem", (Schema,), classattrs) classattrs = {"value": ValueObject(validator_dict[k], many=True)} param_dict[k] = type( @@ -77,7 +74,7 @@ def schemas(self): ) classattrs = {k: fields.Nested(v) for k, v in param_dict.items()} - DefaultsSchema = type("DefaultsSchema", (OrderedSchema,), classattrs) + DefaultsSchema = type("DefaultsSchema", (Schema,), classattrs) defaults_schema = DefaultsSchema() classattrs = { diff --git a/paramtools/tests/test_parameters.py b/paramtools/tests/test_parameters.py index 1c5a6ec..55d0ddf 100644 --- a/paramtools/tests/test_parameters.py +++ b/paramtools/tests/test_parameters.py @@ -166,7 +166,6 @@ def get_defaults(self): assert params.hello_world == "hello world" assert params.label_grid == {"somelabel": [0, 1, 2, 3, 4, 5]} - def test_schema_not_dropped(self, defaults_spec_path): with open(defaults_spec_path, "r") as f: defaults_ = json.loads(f.read()) @@ -379,14 +378,6 @@ def test_specification(self, TestParams, defaults_spec_path): assert spec1["min_int_param"] == exp["min_int_param"]["value"] - def test_is_ordered(self, TestParams): - params = TestParams() - spec1 = params.specification() - assert isinstance(spec1, OrderedDict) - - spec2 = params.specification(meta_data=True, serializable=True) - assert isinstance(spec2, OrderedDict) - def test_specification_query(self, TestParams): params = TestParams() spec1 = params.specification() @@ -1047,7 +1038,9 @@ def test_range_validation_on_list_param(self, TestParams): ] } params.adjust(adj, raise_errors=False) - exp = ["float_list_param[label0=zero, label1=1] [np.float64(-1.0), np.float64(1.0)] < min 0 "] + exp = [ + "float_list_param[label0=zero, label1=1] [np.float64(-1.0), np.float64(1.0)] < min 0 " + ] assert params.errors["float_list_param"] == exp