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

restore public status of NWBMetaDataEncoder encoder #1142

Merged
merged 18 commits into from
Dec 10, 2024

Conversation

h-mayorquin
Copy link
Collaborator

This should fix #1141.

I want to do this after #1139 to minimize conflict errors. This PR has #1139 as base.

@h-mayorquin h-mayorquin self-assigned this Nov 14, 2024
Base automatically changed from support_datetime_on_conversion_options to main November 14, 2024 13:47
@h-mayorquin h-mayorquin marked this pull request as ready for review November 15, 2024 23:34
This encoder extends the default JSONEncoder class and provides custom serialization
for certain data types commonly used in NWB metadata.
"""
class _GenericNeuroconvEncoder(json.JSONEncoder):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bendichter here.

Copy link
Contributor

@alessandratrapani alessandratrapani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me!


return super().default(obj)
# This is used in the Guide so we will keep it public.
NWBMetaDataEncoder = _NWBMetaDataEncoder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a strange pattern. Why not just define it as public to begin with?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to keep things private by default in general. Then we don't have to worry when we refactor, move stuff, change signature, etc. It is less work for us for something that is not our core service and it frees resources for more important stuff.

The problem here is that Ryan was using that one, then we made it private at some point in June which broke something on its end. We are making it public for him here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the issue here:
#1141

Magic was used to solve the compatibility break from path and strings to pydantic with aliases and then that magic broke something else. This is restoring / addressing this.

Comment on lines -46 to 59
class _NWBSourceDataEncoder(_NWBMetaDataEncoder):
class _NWBMetaDataEncoder(_GenericNeuroconvEncoder):
"""
Custom JSON encoder for data interface source data (i.e. kwargs).

This encoder extends the default JSONEncoder class and provides custom serialization
for certain data types commonly used in interface source data.
Custom JSON encoder for NWB metadata.
"""

def default(self, obj):

# Over-write behaviors for Paths
if isinstance(obj, Path):
return str(obj)

return super().default(obj)
class _NWBSourceDataEncoder(_GenericNeuroconvEncoder):
"""
Custom JSON encoder for data interface source data (i.e. kwargs).
"""


class _NWBConversionOptionsEncoder(_NWBMetaDataEncoder):
class _NWBConversionOptionsEncoder(_GenericNeuroconvEncoder):
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a strange pattern. Why define child classes that are identical to the parent class? Why not just use the parent class?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They might diverge and we might not want the same behavior for each of those cases.

Copy link
Collaborator Author

@h-mayorquin h-mayorquin Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that they are private though, I don't mind having the simple case as you want it and then refactoring if and when we need it.

@h-mayorquin h-mayorquin enabled auto-merge (squash) December 10, 2024 16:26
@h-mayorquin h-mayorquin merged commit 1032e15 into main Dec 10, 2024
39 of 40 checks passed
@h-mayorquin h-mayorquin deleted the make_metadata_encoder_public_again branch December 10, 2024 18:21
Copy link

codecov bot commented Dec 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.88%. Comparing base (96dfdff) to head (6577404).
Report is 4 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1142      +/-   ##
==========================================
+ Coverage   90.69%   90.88%   +0.18%     
==========================================
  Files         129      129              
  Lines        8189     8205      +16     
==========================================
+ Hits         7427     7457      +30     
+ Misses        762      748      -14     
Flag Coverage Δ
unittests 90.88% <100.00%> (+0.18%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/neuroconv/basedatainterface.py 95.34% <100.00%> (ø)
...aces/behavior/neuralynx/neuralynx_nvt_interface.py 98.38% <100.00%> (+0.02%) ⬆️
...nv/tools/nwb_helpers/_metadata_and_file_helpers.py 86.57% <100.00%> (-0.09%) ⬇️
...c/neuroconv/tools/testing/data_interface_mixins.py 95.55% <100.00%> (ø)
src/neuroconv/utils/__init__.py 50.00% <ø> (ø)
src/neuroconv/utils/json_schema.py 95.03% <100.00%> (+0.48%) ⬆️

... and 3 files with indirect coverage changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: No ImportError when calling from neuroconv.utils import NWBMetaDataEncoder
3 participants