-
Notifications
You must be signed in to change notification settings - Fork 409
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
Add utility for removing duplicated objects (e.g. keys, clefs) #1454
Conversation
This is a first implementation of what we discussed in #1392. Questions:
|
Can you rename the PR for what it does -- when it gets merged and I need to do the News items, good PR titles are super essential. |
I wouldn't compare the string state, just use equality (x == y) and if there's an issue with what compares as == in a class, we can fix that there. String reps are just for humans not computers. Other than that, looks like it's on the right track. You're going to need to cast to list early or -- better -- make a list of elements to remove and their active sites and then afterwards remove them in bulk -- otherwise the stream needs to be resorted n times for n^2 log n operations instead of n log n operations. If you remove while iterating there are bugs (like popping from a list you're iterating over). |
Thanks. Yes, I resorted to string because when I compared the objects directly before it failed to recognise the equality. I assumed because there was a difference in something like the ID, but it seems that:
So I guess that's fine? If so, the problem must have been something else. |
Also wry mypy, I'm not totally clear on best practice in the |
Looks like you're only using import typing as t
... other imports...
if t.TYPE_CHECKING:
from music21 import stream |
Thanks @jacobtylerwalls for the tip! Caveat is that apparently ... |
Thanks for the notes @mscuthbert and @jacobtylerwalls ... The plot thickens ... Returning to the good practice
As it's the time signature, I wonder if the issue is something to do with I can imagine various work arounds (e.g., with Full comprison fail:
|
Hey Mark. The time signature comparison issue is familiar because I remember it from #823. Until we implement Or, what I hear Myke saying, is that we could implement music21/music21/musicxml/partStaffExporter.py Line 564 in df4bb62
I suggest doing that in a separate PR first to get it in faster. There are some examples in the code base for implementing |
The potential downside of making |
Thanks @jacobtylerwalls for providing this rich and helpful context. Seems like a great fix to me, specifically:
|
I think that I'm going to need a whole equality hierarchy for Music21Object, so that classes can reasonably assume that Will make new PR for that. |
Notably, this means removing time signatures for now while they're problematic. See cuthbertLab#1457
Simplifies nested comparisons and doesn't run for - len 0 ... i.e. not used, - len 1 ... i.e. doesn't change
Ok, here's a clean up that clearly separates out the different issues here and (hopefully) wraps this PR. It looks like ...
... So those two get their own PRs ...
Separating that off, this PR now ...
I'd suggest we
So then the only remaining fail is on lint with:
Not sure how to improve that, especially as there are only two lists and:
|
No. That's not how this project works. |
Thanks for the quick reply @mscuthbert. Of course it's up to you ... but I don't see why not in this case. It may be useful to pursue this a little further as an example case for merge criteria, and to see whether any clarifications or changes are needed to the stated requirements. At a minimum, the discussion would help me continue to serve music21 as best I can. It may well benefit others, both current and (perhaps especially) potential contributors. If this is more appropriate for the group or some other context, then feel free to move there. As I hope will be clear, I offer this in the most constructive spirit possible with the aim of making the development and use of music21 as positive and rewarding as it can be. Criteria for inclusionI know and understand the developer reference guide for contributions and the newer version here. I'm also aware that that's something of a work in progress, with the later file being new, updates being added as we speak, and integrating of those two docs presumably being on the cards? For instance, the expectation to suggest any new contribution and get it approved in advance before developing a PR is in the latter and not the former. In any case, as far as I can see, the conditions stated there have been met in this case. Possible reasons against this merge:
Perhaps I'm missing something. Thanks for clarifying if so. Why do I care? What's the rush? Why does it matter to music21?Obviously we must avoid wasting volunteer contribution time. A few days ago we discussed a near-merge PR that was dormant for only a few weeks before being superseded by a parallel PR on the same topic. Whatever the relative importance of that specific PR, it is significant to think that the process for coordination is not reliable at the work in progress phase. Once a PR is merged, then clearly it has to be taken into consideration for new contributions, but prior to that point, we're susceptible to loosing coordination. Work on v9 will take some time and contributions that have to wait for it are particularly susceptible to this duplicated work, let alone the possibility that contributors will moving on and forget about it, or at least loose clarity on the details. Ok, that's all!Please excuse the long message! I hope it is useful, e.g., by channelling this discussion into more detailed contributor advice, whether or not that involves a change in practice, or simply a clarification. Thanks for your thoughts, here or elsewhere, and here's to a great future for music21 with a wide and happy contributor base. |
Lint: W0102(dangerous-default-value), removeDuplicates] Dangerous default value [] as argument
Co-authored-by: Jacob Walls <[email protected]>
Co-authored-by: Jacob Walls <[email protected]>
Co-authored-by: Jacob Walls <[email protected]>
Co-authored-by: Jacob Walls <[email protected]>
Mypy remains ...
Any tips @jacobtylerwalls ? Maybe something like Keen to be a good citizen ... but not clear to me that that's helpful / worth it here. Thanks for any advice. |
I think diff --git a/music21/stream/tools.py b/music21/stream/tools.py
index d26719acf..20d6a5bff 100644
--- a/music21/stream/tools.py
+++ b/music21/stream/tools.py
@@ -10,6 +10,7 @@
# ------------------------------------------------------------------------------
from __future__ import annotations
+import typing as t
from music21 import clef
from music21 import environment
@@ -17,6 +18,10 @@ from music21 import key
from music21 import meter
from music21 import stream
+if t.TYPE_CHECKING:
+ from music21.base import Music21Object
+
+
environLocal = environment.Environment('stream.tools')
@@ -156,7 +161,7 @@ def removeDuplicates(thisStream: stream.Stream,
supportedClasses = (meter.TimeSignature, key.KeySignature, clef.Clef)
- removalDict = {}
+ removalDict: dict[stream.Stream, list[Music21Object]] = {}
if not inPlace:
thisStream = thisStream.coreCopyAsDerivation('removeDuplicates') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is a cool tool!
Thanks again for the review/s @jacobtylerwalls . |
Thanks, Mark! |
Thanks Mark and Jacob. One thing I just caught now -- should probably have a little patch that if run on an Opus it calls it on each of the .scores (which then will call on each of the .parts). Not a big deal. |
Add utility for removing duplicated objects (e.g. keys, clefs) (cuthbertLab#1454)
No description provided.