feat(python): Add new alpha
, alphanumeric
and digit
selectors
#16310
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.
New selectors, making it even easier to classify column names by character type:
cs.alphanumeric()
: only names composed of letters and digits.cs.alpha()
: only names composed of letters.cs.digit()
: only names composed of digits.One of the nice bonuses in having separate selectors for this is making sure that non-ASCII letters are handled automatically, eg: accented characters in words such as "tweeëntwintig", kanji such as "東京", hangul, etc.
(I also suspect that, even amongst users familiar with regular expressions, a reasonable number wouldn't immediately know the equivalent
cs.matches
pattern^[\p{Alphabetic}]+$
, which is also a little more cryptic in a codebase 🤔)There is an optional flag
ascii_only
if you want to limit the definition of "alphabetic" to ASCII, but having Unicode letters recognised by default is a good out-of-the-box experience for more languages.Examples
Select columns with alphabetic names; note that accented characters and kanji are recognised as valid:
Constrain the definition of "alphabetic" to ASCII characters:
Select columns with non-ASCII alphabetic names :)
Select all columns except for those with alphabetic names:
Select alphanumeric names:
Select alphanumeric names, constraining the definition to ASCII characters: