Source code for tensortrade.feed.api.string.operations
"""operations.py contain functions for streaming string operations."""fromtensortrade.feed.core.baseimportStreamfromtensortrade.feed.api.stringimportString
[docs]@String.register(["capitalize"])defcapitalize(s:"Stream[str]")->"Stream[str]":"""Computes the capitalization of a stream. Parameters ---------- s : `Stream[str]` A string stream. Returns ------- `Stream[str]` A capitalized string stream. """returns.apply(lambdax:x.capitalize()).astype("string")
[docs]@String.register(["upper"])defupper(s:"Stream[str]")->"Stream[str]":"""Computes the uppercase of a string stream. Parameters ---------- s : `Stream[str]` A string stream. Returns ------- `Stream[str]` A uppercase string stream. """returns.apply(lambdax:x.upper()).astype("string")
[docs]@String.register(["lower"])deflower(s:"Stream[str]")->"Stream[str]":"""Computes the lowercase of a string stream. Parameters ---------- s : `Stream[str]` A string stream. Returns ------- `Stream[str]` A lowercase string stream. """returns.apply(lambdax:x.lower()).astype("string")
[docs]@String.register(["slice"])defslice(s:"Stream[str]",start:int,end:int)->"Stream[str]":"""Computes the substring of a string stream. Parameters ---------- s : `Stream[str]` A string stream. start : int The start of the slice. end : int The end of the slice. Returns ------- `Stream[str]` A substring stream. """returns.apply(lambdax:x[start:end]).astype("string")
[docs]@String.register(["cat"])defcat(s:"Stream[str]",word:str)->"Stream[str]":"""Computes the concatenation of a stream with a word. Parameters ---------- s : `Stream[str]` A string stream. word : str A word to concatenate with the `s`. Returns ------- `Stream[str]` A concatenated string stream. """returns.apply(lambdax:x+word).astype("string")
[docs]@String.register(["startswith"])defstartswith(s:"Stream[str]",word:str)->"Stream[bool]":"""Computes the boolean stream of a string starting with a specific value. Parameters ---------- s : `Stream[str]` A string stream. word : str A word that a string value can start with. Returns ------- `Stream[bool]` A boolean stream. """returns.apply(lambdax:x.startswith(word)).astype("bool")
[docs]@String.register(["endswith"])defendswith(s:"Stream[str]",word:str)->"Stream[bool]":"""Computes the boolean stream of a string ending with a specific value. Parameters ---------- s : `Stream[str]` A string stream. word : str A word that a string value can end with. Returns ------- `Stream[bool]` A boolean stream. """returns.apply(lambdax:x.endswith(word)).astype("bool")