From bb5b7a0074c8de09ffc96cee5b12865c3967385c Mon Sep 17 00:00:00 2001 From: mferrera Date: Thu, 26 Sep 2024 13:43:17 +0200 Subject: [PATCH] FIX: Give Optionals a default value --- schema/definitions/0.8.0/schema/fmu_results.json | 9 ++++----- src/fmu/dataio/_model/data.py | 14 +++++++------- src/fmu/dataio/_model/fields.py | 4 +++- src/fmu/dataio/_model/specification.py | 6 +++--- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/schema/definitions/0.8.0/schema/fmu_results.json b/schema/definitions/0.8.0/schema/fmu_results.json index 27b11b41e..78f45f6fd 100644 --- a/schema/definitions/0.8.0/schema/fmu_results.json +++ b/schema/definitions/0.8.0/schema/fmu_results.json @@ -2862,6 +2862,7 @@ "type": "null" } ], + "default": null, "examples": [ "kjhsdfvsdlfk23knerknvk23" ], @@ -2900,8 +2901,7 @@ } }, "required": [ - "relative_path", - "checksum_md5" + "relative_path" ], "title": "File", "type": "object" @@ -5499,7 +5499,6 @@ } }, "required": [ - "attributes", "size" ], "title": "PointSpecification", @@ -7792,6 +7791,7 @@ "type": "null" } ], + "default": null, "examples": [ 1, 9999 @@ -7807,6 +7807,7 @@ "type": "null" } ], + "default": null, "examples": [ 1, 9999 @@ -7824,8 +7825,6 @@ }, "required": [ "columns", - "num_columns", - "num_rows", "size" ], "title": "TableSpecification", diff --git a/src/fmu/dataio/_model/data.py b/src/fmu/dataio/_model/data.py index fc2ee7303..885f35e85 100644 --- a/src/fmu/dataio/_model/data.py +++ b/src/fmu/dataio/_model/data.py @@ -46,10 +46,10 @@ class Time(BaseModel): .. note:: ``data.time`` items can currently hold a maximum of two values.""" - t0: Optional[Timestamp] = None + t0: Optional[Timestamp] = Field(default=None) """The first timestamp. See :class:`Timestamp`.""" - t1: Optional[Timestamp] = None + t1: Optional[Timestamp] = Field(default=None) """The second timestamp. See :class:`Timestamp`.""" @@ -65,16 +65,16 @@ class Seismic(BaseModel): calculation: Optional[str] = Field(default=None, examples=["mean"]) """The type of calculation applied.""" - filter_size: Optional[float] = Field(allow_inf_nan=False, default=None) + filter_size: Optional[float] = Field(default=None, allow_inf_nan=False) """The filter size applied.""" - scaling_factor: Optional[float] = Field(allow_inf_nan=False, default=None) + scaling_factor: Optional[float] = Field(default=None, allow_inf_nan=False) """The scaling factor applied.""" stacking_offset: Optional[str] = Field(default=None, examples=["0-15"]) """The stacking offset applied.""" - zrange: Optional[float] = Field(allow_inf_nan=False, default=None) + zrange: Optional[float] = Field(default=None, allow_inf_nan=False) """The z-range of these data.""" @@ -305,13 +305,13 @@ class Data(BaseModel): """Column names in the table which can be used for indexing. Only applicable if the data object is a table.""" - base: Optional[Layer] = None + base: Optional[Layer] = Field(default=None) """If the data represent an interval, this field can be used to represent its base. See :class:`Layer`. .. note:: ``top`` is required to use with this.""" - top: Optional[Layer] = None + top: Optional[Layer] = Field(default=None) """If the data represent an interval, this field can be used to represent its top. See :class:`Layer`. diff --git a/src/fmu/dataio/_model/fields.py b/src/fmu/dataio/_model/fields.py index f09bbc125..5af412d01 100644 --- a/src/fmu/dataio/_model/fields.py +++ b/src/fmu/dataio/_model/fields.py @@ -103,7 +103,9 @@ class File(BaseModel): ) """The path of a file relative to the case root.""" - checksum_md5: Optional[str] = Field(examples=["kjhsdfvsdlfk23knerknvk23"]) + checksum_md5: Optional[str] = Field( + default=None, examples=["kjhsdfvsdlfk23knerknvk23"] + ) """A valid MD5 checksum of the file.""" size_bytes: Optional[int] = Field(default=None) diff --git a/src/fmu/dataio/_model/specification.py b/src/fmu/dataio/_model/specification.py index 5d6511f20..2e8d93853 100644 --- a/src/fmu/dataio/_model/specification.py +++ b/src/fmu/dataio/_model/specification.py @@ -52,7 +52,7 @@ class SurfaceSpecification(RowColumn): class PointSpecification(BaseModel): """Specifies relevant values describing an xyz points object.""" - attributes: Optional[List[str]] + attributes: Optional[List[str]] = Field(default_factory=list) """List of columns present in a table.""" size: int = Field(examples=[1, 9999]) @@ -65,10 +65,10 @@ class TableSpecification(BaseModel): columns: List[str] """List of columns present in a table.""" - num_columns: Optional[int] = Field(examples=[1, 9999]) + num_columns: Optional[int] = Field(default=None, examples=[1, 9999]) """The number of columns in a table.""" - num_rows: Optional[int] = Field(examples=[1, 9999]) + num_rows: Optional[int] = Field(default=None, examples=[1, 9999]) """The number of rows in a table..""" size: int = Field(examples=[1, 9999])