mt_metadata.common.comment

Classes

Comment

Base class for all metadata objects with Pydantic validation.

Module Contents

class mt_metadata.common.comment.Comment(**data)

Bases: mt_metadata.base.MetadataBase

Base class for all metadata objects with Pydantic validation.

MetadataBase extends DotNotationBaseModel (which inherits from Pydantic’s BaseModel) to provide automatic validation according to metadata standards. It adds functionality beyond dictionaries, supporting JSON, XML, pandas Series, and other formats for metadata interchange.

_skip_equals

Private attribute listing fields to skip in equality comparisons

Type:

list[str]

_fields

Private attribute caching field information

Type:

dict[str, Any]

Notes

  • All field assignments are validated automatically via Pydantic

  • None values are converted to appropriate defaults (empty string or 0.0)

  • Supports nested attribute access via dot notation

  • Thread-safe for read operations after initialization

author: Annotated[str | None, Field(default=None, description='person who authored the comment', alias=None, json_schema_extra={'units': None, 'required': False, 'examples': ['J. Pedantic']})]
time_stamp: Annotated[float | int | numpy.datetime64 | pandas.Timestamp | str | mt_metadata.common.mttime.MTime | None, Field(default_factory=lambda: MTime(time_stamp='1980-01-01T00:00:00+00:00'), description='Date and time of in UTC of when comment was made.', alias=None, json_schema_extra={'units': None, 'required': False, 'examples': ['2020-02-01T09:23:45.453670+00:00']})]
value: Annotated[str | list | None, Field(default=None, description='comment string', alias=None, json_schema_extra={'units': None, 'required': False, 'examples': ['failure at midnight.']})] = None
classmethod validate_time(value, info)

Validate that the value is a valid time.

classmethod validate_value(value, info)

Validate that the value is a valid string or list.

set_variables()

Validate that the value is a valid string.

as_string()

Returns the comment as “{time_stamp} | {author} | {comment}”

Returns:

formatted comment

Return type:

str

from_dict(value, skip_none=False)

Parse input comment assuming “{time_stamp} | {author} | {comment}”

Parameters:
  • value (str) – _description_

  • skip_none (bool, optional) – _description_, by default False

read_dict(input_dict)

can probably use from_dict method instead, but to keep consistency in EMTF XML metadata, this method is used to read the comment from a dictionary.

Parameters:

input_dict (dict) – input dictionary containing comment data

Returns:

None

Return type:

None

to_xml(string=False, required=True)

Convert the Comment instance to XML format.

Parameters:
  • string (bool, optional) – If True, return the XML as a string. If False, return an ElementTree Element.

  • required (bool, optional) – If True, include all required fields.

Returns:

XML representation of the Comment.

Return type:

str | et.Element