pyroid.text¶
Whitespace normalisation and length filtering (pyroid.text).
normalize_whitespace ¶
Collapse every run of whitespace to one space and strip both ends.
Same result as " ".join(s.split()) for every document (whitespace is
exactly what str.isspace() accepts). Unchanged documents are returned
as the original objects; Arrow nulls stay null.
Parameters:
-
x(str | list[str] | tuple[str, ...] | ArrowStrings) –A str, a list or tuple of str, or an Arrow string array/column (
string,large_stringorstring_view). -
threads(int | None, default:None) –Noneuses pyroid's shared thread pool;nruns at mostntasks at once;1runs on the calling thread.
Returns:
-
str | list[str] | tuple[str, ...] | Column[str]–The same kind as
x: str, list, tuple, or apyroid.Columnof strings (large_stringforlarge_stringinput, elsestring).
Raises:
-
InputError–xis not one of the accepted kinds, or holds a non-str item or a non-string Arrow type. -
UnicodeEncodeError–A str contains a lone surrogate.
-
UnicodeDecodeError–An Arrow row is not valid UTF-8.
min_chars ¶
True for each document with at least n characters (len(s) >= n).
A predicate: it never builds new strings, it returns a mask.
Parameters:
-
x(str | list[str] | tuple[str, ...] | ArrowStrings) –A str, a list or tuple of str, or an Arrow string array/column.
-
n(int) –Minimum number of characters (Unicode code points),
>= 0. -
threads(int | None, default:None) –As for
normalize_whitespace.
Returns:
-
bool | list[bool] | tuple[bool, ...] | Column[bool]–bool,
list[bool],tuple[bool, ...], or apyroid.Columnof bools (nulls stay null), matchingx.
Raises:
-
InputError–xornhas the wrong type. -
ValueError–nis negative.