Skip to content

Commit

Permalink
avoids notes_and_rests dataframes with wild empty columns due to the …
Browse files Browse the repository at this point in the history
…score including no rests
  • Loading branch information
johentsch committed Sep 2, 2023
1 parent b383c5d commit 5983fb5
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/ms3/bs4_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2309,10 +2309,17 @@ def nrl(self, recompute: bool = False) -> pd.DataFrame:
recompute: By default, the measures are cached. Pass True to enforce recomputing anew.
"""
if recompute or len(self._nrl) == 0:
nr = pd.concat([self.nl(), self.rl()]).astype(
{col: "Int64" for col in ["tied", "tpc", "midi", "chord_id"]}
)
self._nrl = sort_note_list(nr.reset_index(drop=True))
rl = self.rl()
nl = self.nl()
if len(rl) == 0:
self._nrl = nl
elif len(nl) == 0:
self._nrl = rl
else:
nr = pd.concat([nl, rl]).astype(
{col: "Int64" for col in ["tied", "tpc", "midi", "chord_id"]}
)
self._nrl = sort_note_list(nr.reset_index(drop=True))
return self._nrl

@cache
Expand Down

0 comments on commit 5983fb5

Please sign in to comment.