-
Notifications
You must be signed in to change notification settings - Fork 26
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
Allow np.bool_ as a valid type when bool is specified in spec #505
Conversation
* Fix hdmf-dev#504 * Ref NeurodataWithoutBorders/pynwb#1298 * Include bool as a scalar type
@@ -23,7 +23,7 @@ class DtypeHelper: | |||
# make sure keys are consistent between hdmf.spec.spec.DtypeHelper.primary_dtype_synonyms, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per the comment here, I tried to maintain consistency between the type maps listed. However, it is very possible that there is some side-effect from adding support for np.bool_
that I am not aware of, so I would appreciate if someone could do a double-check for me.
src/hdmf/spec/spec.py
Outdated
@@ -32,7 +32,7 @@ class DtypeHelper: | |||
'long': ["int64", "long"], | |||
'utf': ["text", "utf", "utf8", "utf-8"], | |||
'ascii': ["ascii", "bytes"], | |||
'bool': ["bool"], | |||
'bool': ["bool", "bool_"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'bool': ["bool", "bool_"], | |
'bool': ["bool"], |
This change is not necessary unless we want to add a new alias "bool_" for "bool" for dtype specs in the spec yaml.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, ok, that makes the purpose of primary_dtype_synonyms
more clear, thanks for clarifying.
I added bool_
here in order to have it added to validator.__allowable
(see https://github.com/agencyenterprise/hdmf/blob/enh/np_bool_in_validator/src/hdmf/validate/validator.py#L18-L40), since that seemed like the most minimally invasive way to resolve the issue, but I didn't know the side-effects of updating primary_dtype_synonyms
. Removing bool_
here will make the new test fail, so we need to find another solution.
I originally wanted to do something like this: #203 but that would either require a more significant change to how the validator checks types in check_type
(currently by matching against lists in __allowable
), or make bool
a unique case.
I've found another implementation here which I think is a good middle-ground and relatively consistent with the existing implementation. Let me know what you think.
For the longer term - do you think this solution is acceptable, or should we add an issue to try and bring the type checking in the validator in line with the method used for type checking in docval (#203)?
Your change looks good and is where I would put it as well. Thanks! |
Awesome, thanks @rly! |
* dev: Fix building of Data with no dtype spec and value DataIO wrapping DCI (hdmf-dev#513) Allow np.bool_ as a valid type when bool is specified in spec (hdmf-dev#505) Check for quantity in validator (hdmf-dev#500) added driver option for ros3 (hdmf-dev#506) Use dockerhub authentication (hdmf-dev#432)
* upstream/dev: Fix building of Data with no dtype spec and value DataIO wrapping DCI (hdmf-dev#513) Allow np.bool_ as a valid type when bool is specified in spec (hdmf-dev#505) Check for quantity in validator (hdmf-dev#500) added driver option for ros3 (hdmf-dev#506) Use dockerhub authentication (hdmf-dev#432)
np.bool_
as a valid type whenbool
is specified in a specMotivation
To fix this pynwb issue: NeurodataWithoutBorders/pynwb#1298
As it is currently possible to create an attribute with a
np.bool_
when the spec lists the dtype asbool
, the validator should similarly allownp.bool_
as a valid bool type.While testing, I discovered that a
DatasetBulder
will not accept annp.bool_
as valid data when the dtype isbool
becausebool
is not included as a scalar type. This seemed like an inconsistency to me, so I added it as a scalar type for docval, but please let me know if you disagree and I'll revert the change.How to test the behavior?
Checklist
flake8
from the source directory.