Skip to content

Commit

Permalink
Remove exception on ragged arrays (#17)
Browse files Browse the repository at this point in the history
* remove ragged exception

* remove ragged exception tests

---------

Co-authored-by: Peter Braun <[email protected]>
  • Loading branch information
Bilchreis and Peter Braun authored Nov 18, 2024
1 parent 6d18f86 commit 5fa87de
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 89 deletions.
16 changes: 9 additions & 7 deletions src/secop_ophyd/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,18 +464,20 @@ def __init__(
self.root_type = self.members.root_type
self.members.shape = []
if self.members.ragged:
raise NestedRaggedArray(
"ragged arrays with more than a single dimension are not supported"
)
pass
# raise NestedRaggedArray(
# "ragged arrays with more than a single dimension are not supported"
# )

else:
self.root_type = self.members

if self.array_element and self.ragged:
raise NestedRaggedArray(
"ragged arrays inside of arrays of copmposite datatypes (struct/tuple) "
"are not supported"
)
pass
# raise NestedRaggedArray(
# "ragged arrays inside of arrays of copmposite datatypes (struct/tuple)"
# "are not supported"
# )

def make_numpy_dtype(self) -> tuple:
if self.shape == []:
Expand Down
166 changes: 84 additions & 82 deletions tests/test_dtype.py
Original file line number Diff line number Diff line change
@@ -1,82 +1,84 @@
import pytest
from frappy.datatypes import (
ArrayOf,
BLOBType,
BoolType,
EnumType,
FloatRange,
IntRange,
ScaledInteger,
StringType,
StructOf,
TupleOf,
)

from secop_ophyd.util import NestedRaggedArray, SECoPdtype


def test_nested_ragged_inside_struct_arrays():
ragged = ArrayOf(
StructOf(arr2=ArrayOf(FloatRange(), minlen=0, maxlen=100), name=StringType()),
minlen=0,
maxlen=100,
)

with pytest.raises(NestedRaggedArray):
SECoPdtype(ragged)


def test_nested_ragged_inside_tuple_arrays():
ragged = ArrayOf(
TupleOf(ArrayOf(FloatRange(), minlen=0, maxlen=100), StringType()),
minlen=0,
maxlen=100,
)

with pytest.raises(NestedRaggedArray):
SECoPdtype(ragged)


def test_nested_ragged_arrays():
ragged = ArrayOf(ArrayOf(FloatRange(), minlen=0, maxlen=100), minlen=0, maxlen=100)

with pytest.raises(NestedRaggedArray):
SECoPdtype(ragged)


def test_nested_arrays():

inner_dt_list = [
IntRange(),
FloatRange(),
ScaledInteger(1),
StringType(),
BoolType(),
BLOBType(),
EnumType("test", bla=0, blub=1),
]

dtype_list = ["number", "number", "number", "string", "boolean", "string", "number"]

for innner_dt, dtype in zip(inner_dt_list, dtype_list):

arr_dt = ArrayOf(
ArrayOf(ArrayOf(innner_dt, minlen=5, maxlen=5), minlen=5, maxlen=5),
minlen=0,
maxlen=5,
)

sdtype = SECoPdtype(arr_dt)

assert sdtype.dtype == dtype

ragged_arr = ArrayOf(
ArrayOf(
ArrayOf(IntRange(min=0, max=100), minlen=0, maxlen=5), minlen=5, maxlen=5
),
minlen=5,
maxlen=5,
)

with pytest.raises(NestedRaggedArray):
SECoPdtype(ragged_arr)
# import pytest
# from frappy.datatypes import (
# ArrayOf,
# BLOBType,
# BoolType,
# EnumType,
# FloatRange,
# IntRange,
# ScaledInteger,
# StringType,
# StructOf,
# TupleOf,
# )

# from secop_ophyd.util import NestedRaggedArray, SECoPdtype


# def test_nested_ragged_inside_struct_arrays():
# ragged = ArrayOf(
# StructOf(arr2=ArrayOf(FloatRange(), minlen=0, maxlen=100), name=StringType()),
# minlen=0,
# maxlen=100,
# )

# with pytest.raises(NestedRaggedArray):
# SECoPdtype(ragged)


# def test_nested_ragged_inside_tuple_arrays():
# ragged = ArrayOf(
# TupleOf(ArrayOf(FloatRange(), minlen=0, maxlen=100), StringType()),
# minlen=0,
# maxlen=100,
# )

# with pytest.raises(NestedRaggedArray):
# SECoPdtype(ragged)


# def test_nested_ragged_arrays():
# ragged = ArrayOf(ArrayOf(FloatRange(),
# minlen=0, maxlen=100), minlen=0, maxlen=100)

# with pytest.raises(NestedRaggedArray):
# SECoPdtype(ragged)


# def test_nested_arrays():

# inner_dt_list = [
# IntRange(),
# FloatRange(),
# ScaledInteger(1),
# StringType(),
# BoolType(),
# BLOBType(),
# EnumType("test", bla=0, blub=1),
# ]

# dtype_list = ["number", "number", "number",
# "string", "boolean", "string", "number"]

# for innner_dt, dtype in zip(inner_dt_list, dtype_list):

# arr_dt = ArrayOf(
# ArrayOf(ArrayOf(innner_dt, minlen=5, maxlen=5), minlen=5, maxlen=5),
# minlen=0,
# maxlen=5,
# )

# sdtype = SECoPdtype(arr_dt)

# assert sdtype.dtype == dtype

# ragged_arr = ArrayOf(
# ArrayOf(
# ArrayOf(IntRange(min=0, max=100), minlen=0, maxlen=5), minlen=5, maxlen=5
# ),
# minlen=5,
# maxlen=5,
# )

# with pytest.raises(NestedRaggedArray):
# SECoPdtype(ragged_arr)

0 comments on commit 5fa87de

Please sign in to comment.