@@ -18,7 +18,7 @@ class Modality(enum.Enum):
1818 IMAGE = "image"
1919
2020
21- class KnownContentType (str , enum .Enum ):
21+ class KnownContentType (enum .Enum ):
2222 """Used to specify column's IANA content type in a dataset."""
2323
2424 SMILES = "chemical/x-smiles"
@@ -57,6 +57,13 @@ def _validate_modality(cls, v, values):
5757 v = Modality [v .upper ()]
5858 return v
5959
60+ @field_validator ("content_type" )
61+ def _validate_content_type (cls , v , values ):
62+ """Tries to convert a string to the Enum"""
63+ if isinstance (v , str ):
64+ v = KnownContentType [v .upper ()]
65+ return v
66+
6067 @field_validator ("dtype" )
6168 def _validate_dtype (cls , v ):
6269 """Tries to convert a string to the Enum"""
@@ -69,6 +76,13 @@ def _serialize_modality(self, v: Modality):
6976 """Return the modality as a string, keeping it serializable"""
7077 return v .name
7178
79+ @field_serializer ("content_type" )
80+ def _serialize_content_type (self , v : KnownContentType ):
81+ """Return the content_type as a string, keeping it serializable"""
82+ if v is not None :
83+ v = v .name
84+ return v
85+
7286 @field_serializer ("dtype" )
7387 def _serialize_dtype (self , v : Optional [DTypeLike ]):
7488 """Return the dtype as a string, keeping it serializable"""
0 commit comments