Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept paths in SIJsonEncoder. #3103

Merged
merged 3 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/spikeinterface/core/core_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ def default(self, obj):
if isinstance(obj, BaseExtractor):
return obj.to_dict()

if isinstance(obj, Path):
return str(obj)

if isinstance(obj, Motion):
return obj.to_dict()

Expand Down
29 changes: 21 additions & 8 deletions src/spikeinterface/core/tests/test_jsonification.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
from spikeinterface.core.core_tools import SIJsonEncoder
from spikeinterface.core.generate import generate_recording, generate_sorting


@pytest.fixture(scope="module")
def numpy_generated_recording():
recording = generate_recording()
return recording
from pathlib import Path


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -124,8 +120,25 @@ def test_numpy_dtype_alises_encoding():
json.dumps(np.float32, cls=SIJsonEncoder)


def test_recording_encoding(numpy_generated_recording):
recording = numpy_generated_recording
def test_path_encoding(tmp_path):

temporary_path = tmp_path / "a_path_for_this_test"

json.dumps(temporary_path, cls=SIJsonEncoder)


def test_path_as_annotation(tmp_path):
temporary_path = tmp_path / "a_path_for_this_test"

recording = generate_recording()
recording.annotate(path=temporary_path)

json.dumps(recording, cls=SIJsonEncoder)


def test_recording_encoding():
recording = generate_recording()

json.dumps(recording, cls=SIJsonEncoder)


Expand Down Expand Up @@ -200,4 +213,4 @@ def test_encoding_numpy_scalars_within_nested_extractors_dict(nested_extractor_d

if __name__ == "__main__":
nested_extractor = nested_extractor()
test_encoding_numpy_scalars_within_nested_extractors(nested_extractor_)
test_encoding_numpy_scalars_within_nested_extractors(nested_extractor)
Loading