jessehostetler commited on
Commit
e9a47ca
·
1 Parent(s): ac4cb23

Change Literal to str, because PyArrow doesn't know about literals

Browse files
Files changed (1) hide show
  1. app/api/models.py +8 -1
app/api/models.py CHANGED
@@ -41,7 +41,7 @@ class BinaryMask(pydantic.BaseModel):
41
  maximum compactness. You can use the ``BinaryMask.from_numpy()``
42
  function to convert a 0-1 numpy array to a BinaryMask.
43
  """
44
- mediaType: Literal["image/png"] = pydantic.Field(
45
  description="The IETF Media Type (MIME type) of the data."
46
  )
47
  data: str = pydantic.Field(
@@ -51,6 +51,13 @@ class BinaryMask(pydantic.BaseModel):
51
  pattern=r"^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/][AQgw]==|[A-Za-z0-9+/]{2}[AEIMQUYcgkosw048]=)?$",
52
  )
53
 
 
 
 
 
 
 
 
54
  @staticmethod
55
  def from_numpy(mask: NDArray[np.uint8]) -> BinaryMask:
56
  """Convert a 0-1 numpy array to a BinaryMask.
 
41
  maximum compactness. You can use the ``BinaryMask.from_numpy()``
42
  function to convert a 0-1 numpy array to a BinaryMask.
43
  """
44
+ mediaType: str = pydantic.Field(
45
  description="The IETF Media Type (MIME type) of the data."
46
  )
47
  data: str = pydantic.Field(
 
51
  pattern=r"^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/][AQgw]==|[A-Za-z0-9+/]{2}[AEIMQUYcgkosw048]=)?$",
52
  )
53
 
54
+ @pydantic.field_validator("mediaType", mode="after")
55
+ @classmethod
56
+ def validate_mediaType(cls, value: str) -> str:
57
+ if value != "image/png":
58
+ raise ValueError(".mediaType must be 'image/png'")
59
+ return value
60
+
61
  @staticmethod
62
  def from_numpy(mask: NDArray[np.uint8]) -> BinaryMask:
63
  """Convert a 0-1 numpy array to a BinaryMask.