Skip to content

Commit

Permalink
correctly failing tests for np.str_ in a tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
sneakers-the-rat committed Dec 14, 2024
1 parent d54698f commit 22341c8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/numpydantic/testing/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,27 @@ class SubClass(BasicModel):
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"
),
Expand Down
4 changes: 3 additions & 1 deletion src/numpydantic/testing/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ def make_array(
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"))
Expand Down Expand Up @@ -106,7 +108,7 @@ def make_array(
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:
Expand Down

0 comments on commit 22341c8

Please sign in to comment.