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

Overload isempty method for types.untyped.Set (Issue #561) #616

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ehennestad
Copy link
Collaborator

@ehennestad ehennestad commented Nov 4, 2024

Fix #561

Motivation

See issue #561

How to test the behavior?

>> emptySet = types.untyped.Set();
>> isempty(emptySet)

ans =

  logical

   1

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

ehennestad commented Nov 4, 2024

The following snippet causes a lot of tests to fail, but is not relevant anymore:

matnwb/+io/parseGroup.m

Lines 66 to 70 in 3222f33

if isempty(parsed)
%special case where a directory is simply empty. Return itself but
%empty
parsed(root) = [];
end

The code was embedded in this context:

    %immediately elide prefix all property names with this but only if there are
    %no typed objects in it.
    propnames = keys(props);
    if hasTypes
        parsed = containers.Map({root}, {props});
    else
        parsed = containers.Map;
        for i=1:length(propnames)
            pnm = propnames{i};
            p = props(pnm);
            parsed([root '_' pnm]) = p;
        end
    end
    
    if isempty(parsed)
        %special case where a directory is simply empty.  Return itself but
        %empty
        parsed(root) = [];
    end

It was possible to create a containers.Map object named parsed that was empty, but parsed was later changed (see below) to be a types.untyped.Set which per definition (ref this PR) can not be empty (unless specifically created with types.untyped.Set.empty)

matnwb/+io/parseGroup.m

Lines 56 to 63 in 5aa27d9

parsed = types.untyped.Set(...
[attributeProperties; datasetProperties; groupProperties; linkProperties]);
if isempty(parsed)
%special case where a directory is simply empty. Return itself but
%empty
parsed(root) = [];
end

Code coverage also shows that lines are not covered by tests. Will remove this part

Copy link

codecov bot commented Nov 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.95%. Comparing base (5aa27d9) to head (6bcafd2).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #616      +/-   ##
==========================================
+ Coverage   90.91%   90.95%   +0.04%     
==========================================
  Files         107      107              
  Lines        4753     4752       -1     
==========================================
+ Hits         4321     4322       +1     
+ Misses        432      430       -2     

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

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.

[Feature]: Override isempty for types.untyped.Set
1 participant