-
Notifications
You must be signed in to change notification settings - Fork 407
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
Roman Numerals: Don't substitute d
for 0
in add10
#1635
Roman Numerals: Don't substitute d
for 0
in add10
#1635
Conversation
Thanks for the fix and test! |
For future work with regexes, esp. in such a common code path like RN instantiation, it would be good to do timing tests when considering alternatives. I think without the lookbehind you can get an improvement: >>> from timeit import timeit
>>> timeit("re.sub(r'(?<!\d)0', 'o', 'viio7')", setup='import re')
0.37872337497537956
>>> timeit("re.sub(r'(\\D)0', r'\1o', 'viio7')", setup='import re')
0.324621667037718
>>> timeit("re.sub(r'(?<!\d)0', 'o', 'vii07')", setup='import re')
0.43934187496779487
>>> timeit("re.sub(r'(\\D)0', r'\1o', 'vii07')", setup='import re')
0.3506033340236172 |
If we're worried about speed perhaps it's worth doing a simple membership check to see if
|
commit f457a2b Merge: fdb126c 8b76a3f Author: Michael Scott Asato Cuthbert <[email protected]> Date: Wed Aug 30 22:54:36 2023 -1000 Merge pull request cuthbertLab#1634 from malcolmsailor/add-2-digit-figures TSV converter bug fix: don't add 'd' prefix to 2-digit added tones like `[add13]` commit fdb126c Author: malcolmsailor <[email protected]> Date: Sun Aug 27 10:42:42 2023 -0600 Roman Numerals: Don't substitute `d` for `0` in `add10` (cuthbertLab#1635) commit 8b76a3f Author: Malcolm Sailor <[email protected]> Date: Sat Aug 19 10:20:48 2023 -0400 remove trailing ws commit 9b5e387 Author: Malcolm Sailor <[email protected]> Date: Sat Aug 19 09:50:07 2023 -0400 update commit d3af7bf Author: Malcolm Sailor <[email protected]> Date: Sat Aug 19 08:04:09 2023 -0400 wip commit 3babd94 Author: Malcolm Sailor <[email protected]> Date: Mon Jul 17 14:10:56 2023 -0600 don't match 'add13' when performing dominant 'd' substitution commit 8baa273 Merge: 2a28ab1 9f35bbb Author: Michael Scott Asato Cuthbert <[email protected]> Date: Thu Jul 13 14:07:36 2023 -1000 Merge pull request cuthbertLab#1629 from TimFelixBeyer/patch-5 commit 9f35bbb Author: Tim Beyer <[email protected]> Date: Thu Jul 13 23:56:39 2023 +0200 fix flake commit 4c5ee5f Author: Tim Beyer <[email protected]> Date: Tue Jul 11 23:46:22 2023 +0200 Remove use of hasElement commit 8141355 Author: TimFelix <[email protected]> Date: Sat Jul 8 20:28:08 2023 +0200 Remove uses of `hasElement` commit d43ec76 Author: Tim Beyer <[email protected]> Date: Sat Jul 8 20:16:18 2023 +0200 Speed up __contains__ by 2x and deprecate `hasElement`
add10
annotations (which occur when converting some DCML files) were causing a bug because the 0 was being converted too
, leading to parsing exceptions.This PR updates the replace logic for
0
so as not to match this case, and adds a test case to the unit test.