Skip to content

Commit

Permalink
Drop optional field in ColSpec (mlflow#13703)
Browse files Browse the repository at this point in the history
Signed-off-by: serena-ruan_data <[email protected]>
Signed-off-by: Daniel Lok <[email protected]>
  • Loading branch information
serena-ruan authored and daniellok-db committed Nov 11, 2024
1 parent 806a784 commit 4ce3cfa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 41 deletions.
2 changes: 0 additions & 2 deletions docs/api_reference/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,10 @@
("py:class", "PIL.Image.Image"),
("py:class", "mlflow.deployments.base.BaseDeploymentClient"),
("py:class", "Endpoint"),
("py:class", "mlflow.types.schema.Array"),
("py:class", "mlflow.types.schema.DataType"),
("py:class", "mlflow.types.schema.ColSpec"),
("py:class", "mlflow.types.schema.TensorSpec"),
("py:class", "mlflow.types.schema.Schema"),
("py:class", "mlflow.types.schema.Object"),
("py:class", "mlflow.types.schema.ParamSchema"),
("py:class", "mlflow.types.schema.ParamSpec"),
("py:class", "opentelemetry.trace.span.Span"),
Expand Down
3 changes: 3 additions & 0 deletions docs/api_reference/source/python_api/mlflow.types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ mlflow.types
.. automodule:: mlflow.types.llm
:members:

.. automodule:: mlflow.types.schema
:members: Array, Map, Object

.. automodule:: mlflow.types.llm._BaseDataclass
:undoc-members:
46 changes: 7 additions & 39 deletions mlflow/types/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import importlib.util
import json
import string
import warnings
from copy import deepcopy
from dataclasses import is_dataclass
from enum import Enum
Expand Down Expand Up @@ -662,28 +661,13 @@ class ColSpec:

def __init__(
self,
type: Union[DataType, Array, Object, str],
type: Union[DataType, Array, Object, Map, str],
name: Optional[str] = None,
optional: Optional[bool] = None,
required: Optional[bool] = None, # TODO: update to required=True after deprecating optional
required: bool = True,
):
self._name = name

if optional is not None:
if required is not None:
raise MlflowException(
"Only one of `optional` and `required` can be specified. "
"`optional` is deprecated, please use `required` instead."
)
else:
warnings.warn(
"`optional` is deprecated and will be removed in a future version "
"of MLflow. Use `required` instead.",
category=FutureWarning,
)
self._required = not optional
else:
self._required = True if required is None else required
self._required = required
try:
self._type = DataType[type] if isinstance(type, str) else type
except KeyError:
Expand All @@ -699,7 +683,7 @@ def __init__(
)

@property
def type(self) -> Union[DataType, Array, Object]:
def type(self) -> Union[DataType, Array, Object, Map]:
"""The column data type."""
return self._type

Expand All @@ -712,16 +696,6 @@ def name(self) -> Optional[str]:
def name(self, value: bool) -> None:
self._name = value

@experimental
@property
def optional(self) -> bool:
"""
Whether this column is optional.
.. Warning:: Deprecated. `optional` is deprecated in favor of `required`.
"""
return not self._required

@experimental
@property
def required(self) -> bool:
Expand Down Expand Up @@ -759,25 +733,19 @@ def from_json_dict(cls, **kwargs):
if kwargs["type"] not in [ARRAY_TYPE, OBJECT_TYPE, MAP_TYPE, SPARKML_VECTOR_TYPE]:
return cls(**kwargs)
name = kwargs.pop("name", None)
optional = kwargs.pop("optional", None)
required = kwargs.pop("required", None)
if kwargs["type"] == ARRAY_TYPE:
return cls(
name=name, type=Array.from_json_dict(**kwargs), optional=optional, required=required
)
return cls(name=name, type=Array.from_json_dict(**kwargs), required=required)
if kwargs["type"] == OBJECT_TYPE:
return cls(
name=name,
type=Object.from_json_dict(**kwargs),
optional=optional,
required=required,
)
if kwargs["type"] == MAP_TYPE:
return cls(
name=name, type=Map.from_json_dict(**kwargs), optional=optional, required=required
)
return cls(name=name, type=Map.from_json_dict(**kwargs), required=required)
if kwargs["type"] == SPARKML_VECTOR_TYPE:
return cls(name=name, type=SparkMLVector(), optional=optional, required=required)
return cls(name=name, type=SparkMLVector(), required=required)


class TensorInfo:
Expand Down

0 comments on commit 4ce3cfa

Please sign in to comment.