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

Allow using empty array when indexing on DataStub object #605

Merged
merged 10 commits into from
Feb 11, 2025

Conversation

ehennestad
Copy link
Collaborator

@ehennestad ehennestad commented Oct 31, 2024

Fix #595

Motivation

Fix issue.

How to test the behavior?

See issue #595

Example that works after the fix, but not before:

nwb = NwbFile(...
    'identifier', 'DATASTUB',...
    'session_description', 'test datastub object copy',...
    'session_start_time', datetime());

% Add different datatypes to a table, and try to read them in later
% using empty indexing on a DataStub representation
tableToExport = table( ...
    {'test'}, ... % Cell
    0, ... % Double
    false, ... % Logical
    struct('x', 1, 'y', 1, 'z', 1) ... % Struct (compound)
);
dynamicTable = util.table2nwb(tableToExport);
nwb.acquisition.set('Test', dynamicTable);

nwbExport(nwb, 'testLoadWithEmptyIndices.nwb')

nwbIn = nwbRead('testLoadWithEmptyIndices.nwb', 'ignorecache');

importedTable = nwbIn.acquisition.get('Test');
varNames = transpose( string(importedTable.colnames) );

for iVarName = varNames
    iDataStub = importedTable.vectordata.get(iVarName).data;

    assert(isa(iDataStub, 'types.untyped.DataStub'))
    value = iDataStub([]);
    assert(isempty(value))
    
    if isstruct(tableToExport.(iVarName))
        expectedClass = 'table';
    else
        expectedClass = class(tableToExport.(iVarName));
    end
    assert(isa(value, expectedClass))
end

Checklist

  • Have you ensured the PR description clearly describes the problem and solutions?
  • Have you checked to ensure that there aren't other open or previously closed Pull Requests for the same change?
  • If this PR fixes an issue, is the first line of the PR description fix #XX where XX is the issue number?

@ehennestad
Copy link
Collaborator Author

@lawrence-mbf I would value your input here.

The proposed fix works in the specific situation, but if you have ideas on how to improve this, or if there are things I have overlooked please let me know.

Copy link

codecov bot commented Oct 31, 2024

Codecov Report

Attention: Patch coverage is 76.92308% with 3 lines in your changes missing coverage. Please review.

Project coverage is 95.39%. Comparing base (c3eedb7) to head (e3cfe50).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
+types/+untyped/@DataStub/load_mat_style.m 76.92% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #605      +/-   ##
==========================================
- Coverage   95.44%   95.39%   -0.05%     
==========================================
  Files         137      137              
  Lines        5265     5277      +12     
==========================================
+ Hits         5025     5034       +9     
- Misses        240      243       +3     

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

@ehennestad ehennestad marked this pull request as ready for review February 10, 2025 15:16
@ehennestad ehennestad changed the title 595 Allow using empty indices for datastub Allow using empty indices when indexing on DataStub object Feb 11, 2025
@ehennestad ehennestad changed the title Allow using empty indices when indexing on DataStub object Allow using empty array when indexing on DataStub object Feb 11, 2025
@ehennestad ehennestad merged commit 065dbf8 into main Feb 11, 2025
7 checks passed
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]: DataStub errors out if trying to retrieve data with empty indices
3 participants