GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||
GeezerVison is showing github.com — gh-109638: Fix for significant backtracking in csv.Sniffer by sg3-141-592 · Pull Request #109639 · python/cpython Conversation
|
|
|
||
| # if we see an extra quote between delimiters, we've got a | ||
| # double quoted format | ||
| # in future Python versions this zero width look-ahead assert can be replaced with atomic groups |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Please may you explain this comment?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Sure, this zero-width lookahead assertion change in the Regex can be done with an atomic group which is cleaner and more concise.
# Current change
(,|^)\W*"(?=(?P<zero>[^,|"\n]*))(?P=zero)"[^,|\n]*"\W*(,|$)
# Atomic Group
(,|^)\W*"(?>[^,|"\n]*)"[^,|\n]*"\W*(,|$)
But atomic groups are only supported in Python 3.11 onwards so I avoided using them here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks Sean. This PR (if merged) would be part of Python 3.13, so let's use the better atomic group method.
A
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Sure, I've switched us to the simpler atomic group setup. Performance is identical to the previous fix.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This looks like a good quick fix for the problem.
Ultimately though, these regexs are hard to read and cause a few problems with lists and other items. I think we should be thinking about how to replace the sniffer to have a higher accuracy. (See https://github.com/ws-garcia/CSVsniffer which shows that only 67.54% accuracy). I've posted to dpo on this topic here: https://discuss.python.org/t/rewrite-csv-sniffer
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This PR is stale because it has been open for 30 days with no activity. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thank you for the patch, but I am afraid it does not work.
These regular expressions are gone on the main branch now (gh-83273), but a fix is still needed for the maintenance branches. Excluding the quote character from the character class, as the lookahead variant in the issue does, keeps the detection working and is enough to reduce the time for your example with 60 iterations from 11 s to 0.3 s (the growth is still superlinear, but much slower). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.