Skip to content

Commit 9207d83

Browse files
fix: Handle np.bool_ in insert and fix download_path tests
- Add np.bool_ to isinstance checks in table.py for proper boolean handling during insert (line 536 validate, line 1172 placeholder) - Fix test_attach.py and test_update1.py to use dj.config.override() instead of deprecated download_path argument 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent d5c275d commit 9207d83

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

src/datajoint/table.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ def validate(self, rows, *, ignore_extra_fields=False) -> ValidationResult:
533533
continue
534534

535535
# Numeric NaN check
536-
if attr.numeric and value != "" and not isinstance(value, bool):
536+
if attr.numeric and value != "" and not isinstance(value, (bool, np.bool_)):
537537
try:
538538
if np.isnan(float(value)):
539539
# NaN is allowed - will be converted to NULL
@@ -1169,7 +1169,7 @@ def __make_placeholder(self, name, value, ignore_extra_fields=False, row=None):
11691169
value = json.dumps(value)
11701170
# Numeric - convert to string
11711171
elif attr.numeric:
1172-
value = str(int(value) if isinstance(value, bool) else value)
1172+
value = str(int(value) if isinstance(value, (bool, np.bool_)) else value)
11731173
# Blob - pass through as bytes (use <blob> for automatic serialization)
11741174

11751175
return name, placeholder, value

tests/integration/test_attach.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
def test_attach_attributes(schema_ext, minio_client, tmpdir_factory):
99
"""Test saving files in attachments"""
10+
import datajoint as dj
11+
1012
# create a mock file
1113
table = Attach()
1214
source_folder = tmpdir_factory.mktemp("source")
@@ -23,27 +25,31 @@ def test_attach_attributes(schema_ext, minio_client, tmpdir_factory):
2325

2426
download_folder = Path(tmpdir_factory.mktemp("download"))
2527
keys = table.keys(order_by="KEY")
26-
path1, path2 = table.to_arrays("img", "txt", download_path=download_folder, order_by="KEY")
2728

28-
# verify that different attachment are renamed if their filenames collide
29-
assert path1[0] != path2[0]
30-
assert path1[0] != path1[1]
31-
assert Path(path1[0]).parent == download_folder
32-
with Path(path1[-1]).open("rb") as f:
33-
check1 = f.read()
34-
with Path(path2[-1]).open("rb") as f:
35-
check2 = f.read()
36-
assert data1 == check1
37-
assert data2 == check2
29+
with dj.config.override(download_path=str(download_folder)):
30+
path1, path2 = table.to_arrays("img", "txt", order_by="KEY")
31+
32+
# verify that different attachment are renamed if their filenames collide
33+
assert path1[0] != path2[0]
34+
assert path1[0] != path1[1]
35+
assert Path(path1[0]).parent == download_folder
36+
with Path(path1[-1]).open("rb") as f:
37+
check1 = f.read()
38+
with Path(path2[-1]).open("rb") as f:
39+
check2 = f.read()
40+
assert data1 == check1
41+
assert data2 == check2
3842

39-
# verify that existing files are not duplicated if their filename matches issue #592
40-
p1, p2 = (Attach & keys[0]).fetch1("img", "txt", download_path=download_folder)
41-
assert p1 == path1[0]
42-
assert p2 == path2[0]
43+
# verify that existing files are not duplicated if their filename matches issue #592
44+
p1, p2 = (Attach & keys[0]).fetch1("img", "txt")
45+
assert p1 == path1[0]
46+
assert p2 == path2[0]
4347

4448

4549
def test_return_string(schema_ext, minio_client, tmpdir_factory):
4650
"""Test returning string on fetch"""
51+
import datajoint as dj
52+
4753
# create a mock file
4854
table = Attach()
4955
source_folder = tmpdir_factory.mktemp("source")
@@ -59,6 +65,7 @@ def test_return_string(schema_ext, minio_client, tmpdir_factory):
5965
table.insert1(dict(attach=2, img=attach1, txt=attach2))
6066

6167
download_folder = Path(tmpdir_factory.mktemp("download"))
62-
path1, path2 = table.to_arrays("img", "txt", download_path=download_folder, order_by="KEY")
68+
with dj.config.override(download_path=str(download_folder)):
69+
path1, path2 = table.to_arrays("img", "txt", order_by="KEY")
6370

6471
assert isinstance(path1[0], str)

tests/integration/test_update1.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ def test_update1(tmpdir, schema_update1, mock_stores_update):
8686
# Insert the relative path within the store
8787
Thing.update1(dict(key, img_file=f"{relpath}/{filename}"))
8888

89-
check2 = Thing.fetch1(download_path=tmpdir)
89+
with dj.config.override(download_path=str(tmpdir)):
90+
check2 = Thing.fetch1()
9091
buffer2 = Path(check2["picture"]).read_bytes() # read attachment
9192
# For filepath, fetch returns ObjectRef - read the file through it
9293
filepath_ref = check2["img_file"]

0 commit comments

Comments
 (0)