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

Error in some cases in replace_refs #389

Open
leleogere opened this issue Oct 15, 2024 · 3 comments
Open

Error in some cases in replace_refs #389

leleogere opened this issue Oct 15, 2024 · 3 comments
Assignees

Comments

@leleogere
Copy link

When dealing with ScoreVariant object, it seems to call replace_refs at some point. However, when a reference for an object is not found, it tries to print a warning specifying the start and end of the object o_el. However, it seems that sometimes, o_el is None for some reason, and therefore the code raises a AttributeError: 'NoneType' object has no attribute 'start'.

Commenting out the following two warnings resolves the issue.

warnings.warn(
dedent(
"""reference not found in
o_map: {} start={} end={}, substituting None
""".format(
o_el, o_el.start, o_el.end
)
)
)

warnings.warn(
dedent(
"""reference not found in o_map:
{} start={} end={}, substituting None
""".format(
o, o.start, o.end
)
)
)

Code to reproduce:

from pathlib import Path

import partitura as pt
import partitura.score

score_path = Path("/home/user/nasap-dataset/Schubert/Wanderer_fantasie/xml_score.musicxml")

score = pt.load_musicxml(score_path).parts[0]

# Setup window
start_measure = score.measures[0]
end_measure = score.measures[8]

# Create ScoreVariant
sv = pt.score.ScoreVariant(score)
sv.add_segment(start_measure.start.t, end_measure.end.t)
new_score = sv.create_variant_part()
@sildater
Copy link
Member

Thank you for raising this issue and the code to reproduce it! When I run it I get an error due to the add_segment arguments being integers instead of TimePointobjects. When I correct this line to sv.add_segment(start_measure.start, end_measure.end) I get no error anymore. But this seems unrelated to the issue you observed with replace_refs. Can you check whether the reproducing code needs to be modified?

@leleogere
Copy link
Author

I don't know how what I did with this code, but it does not work indeed! Removing the .t works for this example, but I'm still facing the issue in my codebase (even without the .t when adding the segment). I have not be able to create a minimal reproducible example so far, I will continue to investigate to see if I can spot the error.

So far, it seems that the issue happens when the ReplaceRefMixin._slur_stops array contains a None for some reason (resulting in o_el being None when iterating over the array), but I have not been able to track down where this None comes from. I'll let you know if I can get a small example to reproduce the error.

@leleogere
Copy link
Author

Found it! The issue seems to be caused by pt.score.unfold_part_maximal.

Here is an updated (normally working) script to reproduce the error:

from pathlib import Path

import partitura as pt
import partitura.score

score_path = Path("/home/gerel/Documents/datasets/nasap-dataset/Schubert/Wanderer_fantasie/xml_score.musicxml")

score = pt.load_musicxml(score_path).parts[0]
score = pt.score.unfold_part_maximal(score)

# Setup window
start_measure = score.measures[0]
end_measure = score.measures[1]

# Create ScoreVariant
sv = pt.score.ScoreVariant(score)
sv.add_segment(start_measure.start, end_measure.end)
new_score = sv.create_variant_part()

To debug, I overrode the __setattr__ method of ReplaceRefMixin with the following:

    def __setattr__(self, key, value):
        if hasattr(self, "_ref_attrs") and key in self._ref_attrs and isinstance(value, list) and None in value:
            print(f"{key} set to {value}")
        super().__setattr__(key, value)

and we can see that calling pt.score.unfold_part_maximal seems often put a None in list attributes that are in the replace_refs method, resulting in errors when trying to call .start and .end on the object.

leleogere added a commit to leleogere/partitura that referenced this issue Oct 21, 2024
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

No branches or pull requests

2 participants