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

Draft
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

@ehennestad ehennestad requested a review from bendichter November 4, 2024 20:29
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.

@ehennestad ehennestad marked this pull request as draft November 12, 2024 13:15
@ehennestad
Copy link
Collaborator Author

Current thinking: This should be not be merged as is. A types.untyped.Set is similar to a struct, containers.Map or dictionary in that it holds name-value pairs. Non of the builtin MATLAB types are empty if they have no name-value pairs, i.e s = struct is a scalar, and s = struct.empty is empty.

The same should be true for the Set.

Instead of redefining is empty, I think it would be better to not override size as is currently done, and also to change the custom display for a Set with no elements from:
Empty Set
to:
Set with no elements or Set with no name, value pairs

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