提交 33deba81 authored 作者: Ricardo Vieira's avatar Ricardo Vieira 提交者: Michael Osthege

Raise NotImplementedError when trying to convert MaskedArrays

上级 cbef7d52
......@@ -240,6 +240,9 @@ def convert(x, dtype=None):
The dtype to use for the conversion of `x`.
"""
if isinstance(x, np.ma.MaskedArray):
raise NotImplementedError("MaskedArrays are not supported")
if dtype is not None:
# in this case, the semantics are that the caller is forcing the dtype
x_ = _asarray(x, dtype=dtype)
......
......@@ -65,6 +65,9 @@ def tensor_constructor(
optional `shape` argument will override this default.
"""
if isinstance(value, np.ma.MaskedArray):
raise NotImplementedError("MaskedArrays are not supported")
if broadcastable is not None:
warnings.warn(
"The `broadcastable` keyword is deprecated; use `shape`.",
......
......@@ -537,6 +537,12 @@ def test_constant():
assert np.array_equal(z.data, x_data)
def test_constant_masked_array_not_implemented():
x = np.ma.masked_greater(np.array([1, 2, 3, 4]), 3)
with pytest.raises(NotImplementedError, match="MaskedArrays are not supported"):
constant(x)
class TestAsTensorVariable:
"""
Unit test for ensuring that as_tensor_variable handles Apply objects
......@@ -688,6 +694,13 @@ class TestAsTensorVariable:
with pytest.raises(TypeError):
at.as_tensor(TestOp(matrix(), matrix()))
def test_masked_array_not_implemented(
self,
):
x = np.ma.masked_greater(np.array([1, 2, 3, 4]), 3)
with pytest.raises(NotImplementedError, match="MaskedArrays are not supported"):
at.as_tensor(x)
class TestAlloc:
dtype = config.floatX
......
......@@ -688,3 +688,9 @@ def test_scalar_shared_options():
def test_get_vector_length():
x = pytensor.shared(np.array((2, 3, 4, 5)))
assert get_vector_length(x) == 4
def test_shared_masked_array_not_implemented():
x = np.ma.masked_greater(np.array([1, 2, 3, 4]), 3)
with pytest.raises(NotImplementedError, match="MaskedArrays are not supported"):
pytensor.shared(x)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论