Sanitiser update and fix - #90
Open
dylanjmcconnell wants to merge 4 commits into
Open
Conversation
- simplyfy regex (ignored everything after a whitespace and parenthesis) - updated doc string (make it clear that everything after parenthesis dropped)
…w footnote type - relative simple regex for footnotes like 750[footnote14]
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some of the cells in v7.8 of the workbook have a new type of within-cell footnotes. In addition, previous sanitisation of in-cell comments also silently mis-handles some comments (this effects v7.8 but also some older versions too). This PR address both of these by updating and fixing
sanitisers.pyNew footnote style
There are now square-bracketed footnotes, immediately next to a value (e.g.
750[footnote14]). This pattern not captured by any of the existing sanitisers - so a new one is added as follows:(and the function added to the list of santisers to run)
Mis-handled santisation
_remove_series_notes_after_valuesis intended to handle the common123 (some note)shape. But the existing regex patterns stops at a $ sign (and also : and probably others) - so some things are silently not-sanitised. For example:Is returned as:
(i.e. the bit from the parenthesis to the $ is removed, but not anything after the $ sign)
Have up updated the santiser to capture broader more generic pattern, from:
r"^([0-9\.]+)\s+(?:(\([\w\s\.\<\=\-\/\,]+\)?\s?)+)"to:
r"^([0-9\.]+)\s+\(.*$"This is a much more generic regex - i.e. basically capture anything following whitespace and opening parenthesis - i.e. anything after
<number><whitespace>(. Not just the whitelist of characters in the original (not sure if there was a reason for that original white list?).I did regenerate the example outputs to see if there were negative side effects of this .. I did spot two patterns that are not footnotes, and captured by this (but also - previously there were incorrectly captured as footnotes, and maybe are a different category of problem / issue):
350 (Summer) / 362 (Winter)- now sanitises as350with new regex (and previously as350362 (Winter))4600 (V8: 3,000)- now sanitises as4000with new regex (and previously as4600: 3000))So this PR would make these values go from "incorrectly treated as comments and poorly sanitised", to "incorrectly treated as comments and slightly better sanitised". The reason I say "slightly better" is mainly because it means the the rest of the table has the consistent dyptes (rather the float and str in same col). Perhaps this is better dealt with as a separate issue, if at all (... pretty niche issue at the end of the day, I think). But open to other suggestions.
I did make a table with current output, vs updated output and original text (.. mainly because was hard to spot changes in the git diffs). I've put it here incase it's handy for anyone else to look at too: Comment changes and fixes for workbook 7.8.
Tests:
Added some basic tests for the new / updated functions in
tests/test_sanitisers.py:test_remove_series_notes_after_values_with_special_characterstest_remove_series_bracketed_footnotes.File changes:
src/isp_workbook_parser/sanitisers.pytests/test_sanitisers.pyAnd then a handful of output csvs in the
example_outputcsv folder