mirror of
https://github.com/p2p-ld/numpydantic.git
synced 2025-01-09 21:44:27 +00:00
correctly failing tests for np.str_ in a tuple
This commit is contained in:
parent
d54698fc0f
commit
22341c8b06
2 changed files with 24 additions and 1 deletions
|
@ -126,6 +126,27 @@ DTYPE_CASES = [
|
|||
ValidationCase(annotation_dtype=str, dtype=str, passes=True, id="str-str"),
|
||||
ValidationCase(annotation_dtype=str, dtype=int, passes=False, id="str-int"),
|
||||
ValidationCase(annotation_dtype=str, dtype=float, passes=False, id="str-float"),
|
||||
ValidationCase(
|
||||
annotation_dtype=np.str_,
|
||||
dtype=str,
|
||||
passes=True,
|
||||
id="np_str-str",
|
||||
marks={"np_str", "str"},
|
||||
),
|
||||
ValidationCase(
|
||||
annotation_dtype=np.str_,
|
||||
dtype=np.str_,
|
||||
passes=True,
|
||||
id="np_str-np_str",
|
||||
marks={"np_str", "str"},
|
||||
),
|
||||
ValidationCase(
|
||||
annotation_dtype=(int, np.str_),
|
||||
dtype=str,
|
||||
passes=True,
|
||||
id="tuple_np_str-str",
|
||||
marks={"np_str", "str", "tuple"},
|
||||
),
|
||||
ValidationCase(
|
||||
annotation_dtype=BasicModel, dtype=BasicModel, passes=True, id="model-model"
|
||||
),
|
||||
|
|
|
@ -75,6 +75,8 @@ class HDF5Case(_HDF5MetaCase):
|
|||
data = np.array(array, dtype=dtype)
|
||||
elif dtype is str:
|
||||
data = generator.random(shape).astype(bytes)
|
||||
elif dtype is np.str_:
|
||||
data = generator.random(shape).astype("S32")
|
||||
elif dtype is datetime:
|
||||
data = np.empty(shape, dtype="S32")
|
||||
data.fill(datetime.now(timezone.utc).isoformat().encode("utf-8"))
|
||||
|
@ -106,7 +108,7 @@ class HDF5CompoundCase(_HDF5MetaCase):
|
|||
array_path = "/" + "_".join([str(s) for s in shape]) + "__" + dtype.__name__
|
||||
if array is not None:
|
||||
data = np.array(array, dtype=dtype)
|
||||
elif dtype is str:
|
||||
elif dtype in (str, np.str_):
|
||||
dt = np.dtype([("data", np.dtype("S10")), ("extra", "i8")])
|
||||
data = np.array([("hey", 0)] * np.prod(shape), dtype=dt).reshape(shape)
|
||||
elif dtype is datetime:
|
||||
|
|
Loading…
Reference in a new issue