Skip to content

[Bug]: InspectorOutputJSONEncoder Does Not Serialize get_report_header() Output #396

Open
@garrettmflynn

Description

@garrettmflynn

What happened?

The InspectorOutputJSONEncoder cannot handle the Version object in the output of get_report_header, rendering the output unserializable.

The following code will generate the error reported below:

Code

from nwbinspector import inspect_all
from nwbinspector.nwbinspector import InspectorOutputJSONEncoder
from nwbinspector.inspector_tools import get_report_header

import json

if __name__ == '__main__':
    messages = list(
        inspect_all(
            n_jobs=-2,  # uses number of CPU - 1
            path='/Users/garrettflynn/Documents/Github/freerange/example/backend/datasets/nwb',
        )
    )

    header = get_report_header()
    print(header)
    json_report = dict(header=header, messages=messages)

    print(json.loads(json.dumps(obj=json_report, cls=InspectorOutputJSONEncoder))) # Object of type Version is not JSON serializable

Error

/opt/anaconda3/envs/nwb-guide/lib/python3.10/site-packages/hdmf/spec/namespace.py:531: UserWarning: Ignoring cached namespace 'hdmf-common' version 1.3.0 because version 1.7.0 is already loaded.
  warn("Ignoring cached namespace '%s' version %s because version %s is already loaded."
/opt/anaconda3/envs/nwb-guide/lib/python3.10/site-packages/hdmf/spec/namespace.py:531: UserWarning: Ignoring cached namespace 'core' version 2.2.5 because version 2.6.0-alpha is already loaded.
  warn("Ignoring cached namespace '%s' version %s because version %s is already loaded."
{'Timestamp': '2023-08-24 16:37:31.314017-07:00', 'Platform': 'macOS-13.4.1-x86_64-i386-64bit', 'NWBInspector_version': <Version('0.4.29')>}
Traceback (most recent call last):
  File "/Users/garrettflynn/Documents/Github/nwb-guide/inspectorTest.py", line 19, in <module>
    print(json.loads(json.dumps(obj=json_report, cls=InspectorOutputJSONEncoder))) # Object of type Version is not JSON serializable
  File "/opt/anaconda3/envs/nwb-guide/lib/python3.10/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/opt/anaconda3/envs/nwb-guide/lib/python3.10/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/opt/anaconda3/envs/nwb-guide/lib/python3.10/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/opt/anaconda3/envs/nwb-guide/lib/python3.10/site-packages/nwbinspector/nwbinspector.py", line 47, in default
    return super().default(o)
  File "/opt/anaconda3/envs/nwb-guide/lib/python3.10/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Version is not JSON serializable

Operating System

macOS

Python Version

3.10

Were you streaming with ROS3?

No

Package Versions

altgraph 0.17.3 pyhd8ed1ab_0 conda-forge
aniso8601 9.0.1 pypi_0 pypi
annotated-types 0.5.0 pyhd8ed1ab_0 conda-forge
appdirs 1.4.4 pypi_0 pypi
arrow 1.2.3 pypi_0 pypi
asciitree 0.3.3 pypi_0 pypi
attrs 23.1.0 pyh71513ae_1 conda-forge
bidsschematools 0.7.1 pypi_0 pypi
blessed 1.20.0 pypi_0 pypi
blinker 1.6.2 pypi_0 pypi
boto3 1.28.23 pypi_0 pypi
botocore 1.31.23 pypi_0 pypi
bzip2 1.0.8 h0d85af4_4 conda-forge
ca-certificates 2023.7.22 h8857fd0_0 conda-forge
certifi 2023.7.22 pypi_0 pypi
chardet 5.1.0 pypi_0 pypi
charset-normalizer 3.2.0 pypi_0 pypi
ci-info 0.3.0 pypi_0 pypi
click 8.1.6 pypi_0 pypi
click-didyoumean 0.3.0 pypi_0 pypi
configparser 6.0.0 pypi_0 pypi
contourpy 1.1.0 pypi_0 pypi
cycler 0.11.0 pypi_0 pypi
dandi 0.55.1 pypi_0 pypi
dandischema 0.8.4 pypi_0 pypi
dnspython 2.4.2 pypi_0 pypi
elephant 0.13.0 pypi_0 pypi
email-validator 2.0.0.post2 pypi_0 pypi
entrypoints 0.4 pyhd8ed1ab_0 conda-forge
etelemetry 0.3.0 pypi_0 pypi
exceptiongroup 1.1.2 pypi_0 pypi
fasteners 0.18 pypi_0 pypi
flask 2.3.2 pypi_0 pypi
flask-cors 4.0.0 pypi_0 pypi
flask-restx 1.1.0 pypi_0 pypi
fonttools 4.42.0 pypi_0 pypi
fparse 1.20.1 pypi_0 pypi
fqdn 1.5.1 pypi_0 pypi
fscacher 0.3.0 pypi_0 pypi
h5py 3.9.0 pypi_0 pypi
hdf5storage 0.1.19 pypi_0 pypi
hdmf 3.8.1 pypi_0 pypi
humanize 4.7.0 pypi_0 pypi
icu 72.1 h7336db1_0 conda-forge
idna 3.4 pypi_0 pypi
importlib-metadata 6.8.0 pypi_0 pypi
importlib_resources 6.0.1 pyhd8ed1ab_0 conda-forge
iniconfig 2.0.0 pypi_0 pypi
interleave 0.2.1 pypi_0 pypi
isodate 0.6.1 pypi_0 pypi
isoduration 20.11.0 pypi_0 pypi
itsdangerous 2.1.2 pypi_0 pypi
jaraco-classes 3.3.0 pypi_0 pypi
jinja2 3.1.2 pypi_0 pypi
jmespath 1.0.1 pypi_0 pypi
joblib 1.3.2 pypi_0 pypi
jsonpointer 2.4 pypi_0 pypi
jsonschema 4.18.0 pyhd8ed1ab_0 conda-forge
jsonschema-specifications 2023.7.1 pyhd8ed1ab_0 conda-forge
keyring 24.2.0 pypi_0 pypi
keyrings-alt 5.0.0 pypi_0 pypi
kiwisolver 1.4.4 pypi_0 pypi
lazy-ops 0.2.0 pypi_0 pypi
libblas 3.9.0 17_osx64_openblas conda-forge
libcblas 3.9.0 17_osx64_openblas conda-forge
libcxx 16.0.6 hd57cbcb_0 conda-forge
libffi 3.4.2 h0d85af4_5 conda-forge
libgfortran 5.0.0 12_3_0_h97931a8_1 conda-forge
libgfortran5 12.3.0 hbd3c1fe_1 conda-forge
libiconv 1.17 hac89ed1_0 conda-forge
liblapack 3.9.0 17_osx64_openblas conda-forge
libopenblas 0.3.23 openmp_h429af6e_0 conda-forge
libsqlite 3.42.0 h58db7d2_0 conda-forge
libuv 1.44.2 h0dc2134_1 conda-forge
libxml2 2.11.5 hd95e348_0 conda-forge
libxslt 1.1.37 h20bfa82_1 conda-forge
libzlib 1.2.13 h8a1eda9_5 conda-forge
llvm-openmp 16.0.6 hff08bdf_0 conda-forge
lxml 4.9.3 py310h479f746_0 conda-forge
macholib 1.16.2 pyhd8ed1ab_0 conda-forge
markupsafe 2.1.3 pypi_0 pypi
matplotlib 3.7.2 pypi_0 pypi
mearec 1.9.0 pypi_0 pypi
meautility 1.5.1 pypi_0 pypi
more-itertools 10.1.0 pypi_0 pypi
msgpack-python 1.0.5 py310ha23aa8a_0 conda-forge
natsort 8.4.0 pypi_0 pypi
ncurses 6.4 hf0c8a7f_0 conda-forge
neo 0.12.0 pypi_0 pypi
neuroconv 0.4.2 pypi_0 pypi
nodejs 18.16.1 h46e3395_0 conda-forge
numcodecs 0.11.0 py310h7a76584_1 conda-forge
numpy 1.25.2 py310h7451ae0_0 conda-forge
nwbinspector 0.4.29 pypi_0 pypi
openssl 3.1.2 h8a1eda9_0 conda-forge
packaging 21.3 pypi_0 pypi
pandas 2.0.3 pypi_0 pypi
pillow 10.0.0 pypi_0 pypi
pip 23.2.1 pyhd8ed1ab_0 conda-forge
pkgutil-resolve-name 1.3.10 pyhd8ed1ab_0 conda-forge
pluggy 1.2.0 pypi_0 pypi
probeinterface 0.2.17 pypi_0 pypi
psutil 5.9.5 pypi_0 pypi
pycryptodomex 3.18.0 pypi_0 pypi
pydantic 1.10.12 pypi_0 pypi
pydantic-core 2.1.2 py310h3461e44_0 conda-forge
pyedflib 0.1.32 py310h936d966_0 conda-forge
pyinstaller 5.13.0 py310hb69a1aa_0 conda-forge
pyinstaller-hooks-contrib 2023.6 pyhd8ed1ab_0 conda-forge
pyintan 0.3.0 pypi_0 pypi
pymatreader 0.0.32 pypi_0 pypi
pynwb 2.4.0 pypi_0 pypi
pyopenephys 1.1.6 pypi_0 pypi
pyout 0.7.3 pypi_0 pypi
pyparsing 3.0.9 pypi_0 pypi
pytest 7.4.0 pypi_0 pypi
python 3.10.12 had23ca6_0_cpython conda-forge
python-dateutil 2.8.2 pypi_0 pypi
python_abi 3.10 3_cp310 conda-forge
pytz 2023.3 pypi_0 pypi
pyyaml 6.0.1 pypi_0 pypi
quantities 0.14.1 pypi_0 pypi
readline 8.2 h9e318b2_1 conda-forge
referencing 0.30.2 pyhd8ed1ab_0 conda-forge
requests 2.31.0 pypi_0 pypi
rfc3339-validator 0.1.4 pypi_0 pypi
rfc3987 1.3.8 pypi_0 pypi
rpds-py 0.9.2 py310h3461e44_0 conda-forge
ruamel-yaml 0.17.32 pypi_0 pypi
ruamel-yaml-clib 0.2.7 pypi_0 pypi
s3transfer 0.6.1 pypi_0 pypi
scipy 1.11.2 pypi_0 pypi
semantic-version 2.10.0 pypi_0 pypi
setuptools 68.0.0 pyhd8ed1ab_0 conda-forge
six 1.16.0 pypi_0 pypi
spikeextractors 0.9.11 pypi_0 pypi
spikeinterface 0.98.2 pypi_0 pypi
tenacity 8.2.2 pypi_0 pypi
threadpoolctl 3.2.0 pypi_0 pypi
tk 8.6.12 h5dbffcc_0 conda-forge
tomli 2.0.1 pypi_0 pypi
tqdm 4.66.0 pypi_0 pypi
typing-extensions 4.7.1 hd8ed1ab_0 conda-forge
typing_extensions 4.7.1 pyha770c72_0 conda-forge
tzdata 2023.3 pypi_0 pypi
uri-template 1.3.0 pypi_0 pypi
urllib3 1.26.16 pypi_0 pypi
wcwidth 0.2.6 pypi_0 pypi
webcolors 1.13 pypi_0 pypi
werkzeug 2.3.6 pypi_0 pypi
wheel 0.41.1 pyhd8ed1ab_0 conda-forge
xmltodict 0.13.0 pypi_0 pypi
xz 5.2.6 h775f41a_0 conda-forge
zarr 2.16.0 pypi_0 pypi
zarr-checksum 0.2.9 pypi_0 pypi
zipp 3.16.2 pyhd8ed1ab_0 conda-forge
zlib 1.2.13 h8a1eda9_5 conda-forge

Code of Conduct

  • I agree to follow this project's Code of Conduct
  • Have you ensured this bug was not already reported?
  • To the best of your ability, have you ensured this is a bug within the code that checks the NWBFile, rather than a bug in the NWBFile reader (e.g., PyNWB or MatNWB)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    category: bugerrors in the code or code behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions