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

Return can_read as False if no nwbfile version is found #1934

Merged
merged 6 commits into from
Jul 18, 2024

Conversation

stephprince
Copy link
Contributor

@stephprince stephprince commented Jul 15, 2024

Motivation

Fix #1919. The can_read method would previously throw a TypeError if no nwbfile version was found. It now returnsFalse instead.

I also added additional tests for can_read to improve code coverage.

How to test the behavior?

from h5py import File
from pynwb import NWBHDF5IO
from pynwb.testing.mock.file import mock_NWBFile

nwbfile = mock_NWBFile()
path = 'test.nwb'

with NWBHDF5IO(path, 'w') as io:
    io.write(nwbfile)
    
with File(path, mode='a') as io:
    del io.attrs['nwb_version']

print(f'{NWBHDF5IO.can_read(path) = }')

Checklist

  • Did you update CHANGELOG.md with your changes?
  • Have you checked our Contributing document?
  • Have you ensured the PR clearly describes the problem and the solution?
  • Is your contribution compliant with our coding style? This can be checked running ruff check . && codespell from the source directory.
  • Have you checked to ensure that there aren't other open Pull Requests for the same change?
  • Have you included the relevant issue number using "Fix #XXX" notation where XXX is the issue number? By including "Fix #XXX" you allow GitHub to close issue #XXX when the PR is merged.

Copy link

codecov bot commented Jul 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.20%. Comparing base (570fb3b) to head (c69688c).
Report is 17 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1934      +/-   ##
==========================================
+ Coverage   91.91%   92.20%   +0.28%     
==========================================
  Files          27       27              
  Lines        2648     2656       +8     
  Branches      691      693       +2     
==========================================
+ Hits         2434     2449      +15     
+ Misses        141      134       -7     
  Partials       73       73              
Flag Coverage Δ
integration 73.15% <100.00%> (+0.34%) ⬆️
unit 83.77% <11.11%> (-0.22%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@stephprince stephprince marked this pull request as ready for review July 15, 2024 23:22
@mavaylon1
Copy link
Collaborator

@stephprince It may be informative to have a distinction between an old file and an invalid file. I think having a warning plus the return false would be better for old files.

@stephprince
Copy link
Contributor Author

@mavaylon1 added some warnings for when the file can be read by h5py but not PyNWB

@stephprince stephprince merged commit a9f6332 into dev Jul 18, 2024
25 checks passed
@stephprince stephprince deleted the fix-can-read-return branch July 18, 2024 00:41
@h-mayorquin
Copy link
Contributor

Thanks for working on this guys.

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

Successfully merging this pull request may close these issues.

[Bug] NWBHDF5IO.can_read() fails for missing version
3 participants