Skip to content

Commit 87aaefd

Browse files
committed
[feat] auto-cast when binType is defined
1 parent 2d1c28f commit 87aaefd

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
- Copyright: (C) Qianqian Fang (2019-2026) <q.fang at neu.edu>
66
- License: Apache License, Version 2.0
7-
- Version: 0.9.1
7+
- Version: 0.9.2
88
- URL: https://github.com/NeuroJSON/pyjdata
99
- Acknowledgement: This project is supported by US National Institute of Health (NIH)
1010
grant [U24-NS124027](https://reporter.nih.gov/project-details/10308329)

jdata/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
from .jschema import jsonschema
124124
from .neurojson import neuroj, neurojgui
125125

126-
__version__ = "0.9.1"
126+
__version__ = "0.9.2"
127127
__all__ = [
128128
"loadjson",
129129
"savejson",

jdata/jdict.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,15 @@ def __le__(self, value):
293293
if schema:
294294
subschema = jsonschema(schema, None, getsubschema=currentpath)
295295
if subschema:
296+
# Auto-cast if binType is defined
297+
if isinstance(subschema, dict) and "binType" in subschema:
298+
bintype = subschema["binType"]
299+
if not isinstance(value, np.ndarray) or value.dtype.name != bintype:
300+
try:
301+
value = np.asarray(value, dtype=bintype)
302+
except (ValueError, TypeError):
303+
pass
304+
296305
valid, errs = jsonschema(value, subschema, rootschema=schema)
297306
if not valid:
298307
raise ValueError(

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
setup(
77
name="jdata",
88
packages=["jdata"],
9-
version="0.9.1",
9+
version="0.9.2",
1010
license="Apache license 2.0",
1111
description="JSON/binary JSON formats for exchanging Python and Numpy data",
1212
long_description=readme,

0 commit comments

Comments
 (0)