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

problem validating bool #1298

Closed
bendichter opened this issue Sep 20, 2020 · 3 comments
Closed

problem validating bool #1298

bendichter opened this issue Sep 20, 2020 · 3 comments
Labels
category: bug errors in the code or code behavior topic: validator issues related to validation of files

Comments

@bendichter
Copy link
Contributor

Running validation on the Neuropixel file found here reveals an issue with the validator when validating a boolean value. It appears there is a confusion between bool and bool_.

$ python -m pynwb.validate /Volumes/easystore5T/data/Allen/neuropixel/sub-699733573_ses-715093703.nwb
Validating /Volumes/easystore5T/data/Allen/neuropixel/sub-699733573_ses-715093703.nwb against cached namespace information using namespace ndx-aibs-ecephys.
 - found the following errors:
EcephysElectrodeGroup/has_lfp_data (general/extracellular_ephys/probeA.has_lfp_data): incorrect type - expected 'bool', got 'bool_'
EcephysElectrodeGroup/has_lfp_data (general/extracellular_ephys/probeB.has_lfp_data): incorrect type - expected 'bool', got 'bool_'
EcephysElectrodeGroup/has_lfp_data (general/extracellular_ephys/probeC.has_lfp_data): incorrect type - expected 'bool', got 'bool_'
EcephysElectrodeGroup/has_lfp_data (general/extracellular_ephys/probeD.has_lfp_data): incorrect type - expected 'bool', got 'bool_'
EcephysElectrodeGroup/has_lfp_data (general/extracellular_ephys/probeE.has_lfp_data): incorrect type - expected 'bool', got 'bool_'
EcephysElectrodeGroup/has_lfp_data (general/extracellular_ephys/probeF.has_lfp_data): incorrect type - expected 'bool', got 'bool_'
@bendichter bendichter added category: bug errors in the code or code behavior topic: validator issues related to validation of files labels Sep 20, 2020
@dsleiter
Copy link
Contributor

@bendichter I looked into this, and here's what I believe is going on:

  1. the spec for EcephysElectrodeGroup has a dtype of bool for attribute has_lfp_data

    {'name': 'has_lfp_data', 'doc': 'Indicates availability of LFP data', 'dtype': 'bool'}

  2. the type of the value for has_lfp_data in this file is np.bool_
  3. it looks to me like ObjectMapper always converts bool to np.bool_ when writing to the file (is this correct?)
  4. In addition, the user could have explicitly passed in an np.bool_ when creating the EcephysElectrodeGroup object because docval explicitly allows np.bool_ to pass validation when the type is specified as bool
    def __is_bool(value):
        return isinstance(value, bool) or isinstance(value, np.bool_)
  5. however, hdmf.validate.validator does not allow np.bool_ to pass validation when the dtype in the spec is bool

It seems like the solution here should be to update the validator in hdmf.validate.validator to allow np.bool_ as a valid dtype when the spec defines the dtype as bool, do you agree? If so, I'll add the issue to hdmf and work on a PR.

@bendichter
Copy link
Contributor Author

@dsleiter thanks for tracking this down. I agree, it sounds like allowing np.bool_ to count as a bool in hdmf.validate.validator would fix the problem.

@dsleiter
Copy link
Contributor

A fix for this has been implemented here: hdmf-dev/hdmf#505 , and should be available as of the next hdmf version (currently planned to be 2.4.0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: bug errors in the code or code behavior topic: validator issues related to validation of files
Projects
None yet
Development

No branches or pull requests

2 participants