Skip to content

Commit

Permalink
fix: remove invalid boundary?
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com>
  • Loading branch information
aarnphm committed Nov 9, 2022
1 parent 2d2cc0c commit e0e1a8d
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 47 deletions.
9 changes: 0 additions & 9 deletions src/bentoml/_internal/io_descriptors/numpy.py
Expand Up @@ -216,15 +216,6 @@ def __init__(
shape: tuple[int, ...] | None = None,
enforce_shape: bool = False,
):
if enforce_dtype and not dtype:
raise InvalidArgument(
"'dtype' must be specified when 'enforce_dtype=True'"
) from None
if enforce_shape and not shape:
raise InvalidArgument(
"'shape' must be specified when 'enforce_shape=True'"
) from None

if dtype and not isinstance(dtype, np.dtype):
# Convert from primitive type or type string, e.g.: np.dtype(float) or np.dtype("float64")
try:
Expand Down
22 changes: 0 additions & 22 deletions src/bentoml/_internal/io_descriptors/pandas.py
Expand Up @@ -325,19 +325,6 @@ def __init__(
enforce_shape: bool = False,
default_format: t.Literal["json", "parquet", "csv"] = "json",
):
if enforce_dtype and dtype is None:
raise ValueError(
"'dtype' must be specified if 'enforce_dtype' is True"
) from None
if enforce_shape and shape is None:
raise ValueError(
"'shape' must be specified if 'enforce_shape' is True"
) from None
if apply_column_names and columns is None:
raise ValueError(
"'columns' must be specified if 'apply_column_names' is True"
) from None

self._orient: ext.DataFrameOrient = orient
self._columns = columns
self._apply_column_names = apply_column_names
Expand Down Expand Up @@ -826,15 +813,6 @@ def __init__(
shape: tuple[int, ...] | None = None,
enforce_shape: bool = False,
):
if enforce_dtype and dtype is None:
raise ValueError(
"'dtype' must be specified if 'enforce_dtype' is True"
) from None
if enforce_shape and shape is None:
raise ValueError(
"'shape' must be specified if 'enforce_shape' is True"
) from None

self._orient: ext.SeriesOrient = orient
self._dtype = dtype
self._enforce_dtype = enforce_dtype
Expand Down
17 changes: 1 addition & 16 deletions tests/unit/_internal/io/test_numpy.py
Expand Up @@ -10,7 +10,6 @@

from bentoml.io import NumpyNdarray
from bentoml.exceptions import BadInput
from bentoml.exceptions import InvalidArgument
from bentoml.exceptions import BentoMLException
from bentoml._internal.service.openapi.specification import Schema

Expand All @@ -29,7 +28,7 @@ class ExampleGeneric(str, np.generic):


example = np.zeros((2, 2, 3, 2))
from_example = NumpyNdarray.from_sample(example)
from_example = NumpyNdarray.from_sample(example, enforce_dtype=True, enforce_shape=True)


def test_invalid_dtype():
Expand All @@ -43,15 +42,6 @@ def test_invalid_dtype():
assert "expects a 'numpy.array'" in str(e.value)


def test_invalid_init():
with pytest.raises(InvalidArgument) as exc_info:
NumpyNdarray(enforce_dtype=True)
assert "'dtype' must be specified" in str(exc_info.value)
with pytest.raises(InvalidArgument) as exc_info:
NumpyNdarray(enforce_shape=True)
assert "'shape' must be specified" in str(exc_info.value)


@pytest.mark.parametrize("dtype, expected", [("float", "number"), (">U8", "integer")])
def test_numpy_to_openapi_types(dtype: str, expected: str):
assert NumpyNdarray(dtype=dtype)._openapi_types() == expected # type: ignore (private functions warning)
Expand Down Expand Up @@ -112,8 +102,6 @@ def test_numpy_openapi_example():

def test_verify_numpy_ndarray(caplog: LogCaptureFixture):
partial_check = partial(from_example.validate_array, exception_cls=BentoMLException)
from_example._enforce_dtype = True
from_example._enforce_shape = True

with pytest.raises(BentoMLException) as ex:
partial_check(np.array(["asdf"]))
Expand All @@ -125,9 +113,6 @@ def test_verify_numpy_ndarray(caplog: LogCaptureFixture):

# test cases where reshape is failed
example = NumpyNdarray.from_sample(np.ones((2, 2, 3)))
# Note that from_sample now lazy load the IO descriptor
example._enforce_shape = False
example._enforce_dtype = False
with caplog.at_level(logging.DEBUG):
example.validate_array(np.array("asdf"))
assert "Failed to reshape" in caplog.text
Expand Down

0 comments on commit e0e1a8d

Please sign in to comment.