Class: Polars::StringExpr
- Inherits:
-
Object
- Object
- Polars::StringExpr
- Defined in:
- lib/polars/string_expr.rb
Overview
Namespace for string related expressions.
Instance Method Summary collapse
-
#contains(pattern, literal: false, strict: true) ⇒ Expr
Check if string contains a substring that matches a regex.
-
#contains_any(patterns, ascii_case_insensitive: false) ⇒ Expr
Use the aho-corasick algorithm to find matches.
-
#count_matches(pattern, literal: false) ⇒ Expr
Count all successive non-overlapping regex matches.
-
#decode(encoding, strict: true) ⇒ Expr
Decode a value using the provided encoding.
-
#encode(encoding) ⇒ Expr
Encode a value using the provided encoding.
-
#ends_with(suffix) ⇒ Expr
Check if string values end with a substring.
-
#escape_regex ⇒ Expr
Returns string values with all regular expression meta characters escaped.
-
#extract(pattern, group_index: 1) ⇒ Expr
Extract the target capture group from provided patterns.
-
#extract_all(pattern) ⇒ Expr
Extracts all matches for the given regex pattern.
-
#extract_groups(pattern) ⇒ Expr
Extract all capture groups for the given regex pattern.
-
#extract_many(patterns, ascii_case_insensitive: false, overlapping: false, leftmost: false) ⇒ Expr
Use the Aho-Corasick algorithm to extract many matches.
-
#find(pattern, literal: false, strict: true) ⇒ Expr
Return the bytes offset of the first substring matching a pattern.
-
#find_many(patterns, ascii_case_insensitive: false, overlapping: false, leftmost: false) ⇒ Expr
Use the Aho-Corasick algorithm to find many matches.
-
#head(n) ⇒ Expr
Return the first n characters of each string in a String Series.
-
#join(delimiter = nil, ignore_nulls: true) ⇒ Expr
Vertically concat the values in the Series to a single string value.
-
#json_decode(dtype, infer_schema_length: nil) ⇒ Expr
Parse string values as JSON.
-
#json_path_match(json_path) ⇒ Expr
Extract the first match of json string with provided JSONPath expression.
-
#len_bytes ⇒ Expr
Get length of the strings as
:u32(as number of bytes). -
#len_chars ⇒ Expr
Get length of the strings as
:u32(as number of chars). -
#normalize(form = "NFC") ⇒ Expr
Returns the Unicode normal form of the string values.
-
#pad_end(length, fill_char = " ") ⇒ Expr
Pad the end of the string until it reaches the given length.
-
#pad_start(length, fill_char = " ") ⇒ Expr
Pad the start of the string until it reaches the given length.
-
#replace(pattern, value, literal: false, n: 1) ⇒ Expr
Replace first matching regex/literal substring with a new string value.
-
#replace_all(pattern, value, literal: false) ⇒ Expr
Replace all matching regex/literal substrings with a new string value.
-
#replace_many(patterns, replace_with = NO_DEFAULT, ascii_case_insensitive: false, leftmost: false) ⇒ Expr
Use the aho-corasick algorithm to replace many matches.
-
#reverse ⇒ Expr
Returns string values in reversed order.
-
#slice(offset, length = nil) ⇒ Expr
Create subslices of the string values of a Utf8 Series.
-
#split(by, inclusive: false, literal: true, strict: true) ⇒ Expr
Split the string by a substring.
-
#split_exact(by, n, inclusive: false) ⇒ Expr
Split the string by a substring using
nsplits. -
#splitn(by, n) ⇒ Expr
Split the string by a substring, restricted to returning at most
nitems. -
#starts_with(prefix) ⇒ Expr
Check if string values start with a substring.
-
#strip_chars(characters = nil) ⇒ Expr
Remove leading and trailing whitespace.
-
#strip_chars_end(characters = nil) ⇒ Expr
Remove trailing whitespace.
-
#strip_chars_start(characters = nil) ⇒ Expr
Remove leading whitespace.
-
#strip_prefix(prefix) ⇒ Expr
Remove prefix.
-
#strip_suffix(suffix) ⇒ Expr
Remove suffix.
-
#strptime(dtype, format = nil, strict: true, exact: true, cache: true, ambiguous: "raise") ⇒ Expr
Parse a Utf8 expression to a Date/Datetime/Time type.
-
#tail(n) ⇒ Expr
Return the last n characters of each string in a String Series.
-
#to_date(format = nil, strict: true, exact: true, cache: true) ⇒ Expr
Convert a Utf8 column into a Date column.
-
#to_datetime(format = nil, time_unit: nil, time_zone: nil, strict: true, exact: true, cache: true, ambiguous: "raise") ⇒ Expr
Convert a Utf8 column into a Datetime column.
-
#to_decimal(scale:) ⇒ Expr
Convert a String column into a Decimal column.
-
#to_integer(base: 10, dtype: Int64, strict: true) ⇒ Expr
Convert an Utf8 column into an Int64 column with base radix.
-
#to_lowercase ⇒ Expr
Transform to lowercase variant.
-
#to_time(format = nil, strict: true, cache: true) ⇒ Expr
Convert a Utf8 column into a Time column.
-
#to_titlecase ⇒ Expr
Transform to titlecase variant.
-
#to_uppercase ⇒ Expr
Transform to uppercase variant.
-
#zfill(length) ⇒ Expr
Fills the string with zeroes.
Instance Method Details
#contains(pattern, literal: false, strict: true) ⇒ Expr
Check if string contains a substring that matches a regex.
785 786 787 788 |
# File 'lib/polars/string_expr.rb', line 785 def contains(pattern, literal: false, strict: true) pattern = Utils.parse_into_expression(pattern, str_as_lit: true) Utils.wrap_expr(_rbexpr.str_contains(pattern, literal, strict)) end |
#contains_any(patterns, ascii_case_insensitive: false) ⇒ Expr
Use the aho-corasick algorithm to find matches.
This version determines if any of the patterns find a match.
1674 1675 1676 1677 1678 1679 |
# File 'lib/polars/string_expr.rb', line 1674 def contains_any(patterns, ascii_case_insensitive: false) patterns = Utils.parse_into_expression(patterns, str_as_lit: false) Utils.wrap_expr( _rbexpr.str_contains_any(patterns, ascii_case_insensitive) ) end |
#count_matches(pattern, literal: false) ⇒ Expr
Count all successive non-overlapping regex matches.
1220 1221 1222 1223 |
# File 'lib/polars/string_expr.rb', line 1220 def count_matches(pattern, literal: false) pattern = Utils.parse_into_expression(pattern, str_as_lit: true) Utils.wrap_expr(_rbexpr.str_count_matches(pattern, literal)) end |
#decode(encoding, strict: true) ⇒ Expr
Decode a value using the provided encoding.
1032 1033 1034 1035 1036 1037 1038 1039 1040 |
# File 'lib/polars/string_expr.rb', line 1032 def decode(encoding, strict: true) if encoding == "hex" Utils.wrap_expr(_rbexpr.str_hex_decode(strict)) elsif encoding == "base64" Utils.wrap_expr(_rbexpr.str_base64_decode(strict)) else raise ArgumentError, "encoding must be one of {{'hex', 'base64'}}, got #{encoding}" end end |
#encode(encoding) ⇒ Expr
Encode a value using the provided encoding.
1063 1064 1065 1066 1067 1068 1069 1070 1071 |
# File 'lib/polars/string_expr.rb', line 1063 def encode(encoding) if encoding == "hex" Utils.wrap_expr(_rbexpr.str_hex_encode) elsif encoding == "base64" Utils.wrap_expr(_rbexpr.str_base64_encode) else raise ArgumentError, "encoding must be one of {{'hex', 'base64'}}, got #{encoding}" end end |
#ends_with(suffix) ⇒ Expr
Check if string values end with a substring.
887 888 889 890 |
# File 'lib/polars/string_expr.rb', line 887 def ends_with(suffix) suffix_rbexpr = Utils.parse_into_expression(suffix, str_as_lit: true) Utils.wrap_expr(_rbexpr.str_ends_with(suffix_rbexpr)) end |
#escape_regex ⇒ Expr
Returns string values with all regular expression meta characters escaped.
410 411 412 |
# File 'lib/polars/string_expr.rb', line 410 def escape_regex Utils.wrap_expr(_rbexpr.str_escape_regex) end |
#extract(pattern, group_index: 1) ⇒ Expr
Extract the target capture group from provided patterns.
1101 1102 1103 1104 |
# File 'lib/polars/string_expr.rb', line 1101 def extract(pattern, group_index: 1) pattern = Utils.parse_into_expression(pattern, str_as_lit: true) Utils.wrap_expr(_rbexpr.str_extract(pattern, group_index)) end |
#extract_all(pattern) ⇒ Expr
Extracts all matches for the given regex pattern.
Extracts each successive non-overlapping regex match in an individual string as an array.
1133 1134 1135 1136 |
# File 'lib/polars/string_expr.rb', line 1133 def extract_all(pattern) pattern = Utils.parse_into_expression(pattern, str_as_lit: true) Utils.wrap_expr(_rbexpr.str_extract_all(pattern)) end |
#extract_groups(pattern) ⇒ Expr
Extract all capture groups for the given regex pattern.
1190 1191 1192 |
# File 'lib/polars/string_expr.rb', line 1190 def extract_groups(pattern) Utils.wrap_expr(_rbexpr.str_extract_groups(pattern)) end |
#extract_many(patterns, ascii_case_insensitive: false, overlapping: false, leftmost: false) ⇒ Expr
This method supports matching on string literals only, and does not support regular expression matching.
Use the Aho-Corasick algorithm to extract many matches.
1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 |
# File 'lib/polars/string_expr.rb', line 1841 def extract_many( patterns, ascii_case_insensitive: false, overlapping: false, leftmost: false ) if overlapping && leftmost msg = "can not match overlapping patterns when leftmost == true" raise ArgumentError, msg end patterns = Utils.parse_into_expression(patterns, str_as_lit: false) Utils.wrap_expr( _rbexpr.str_extract_many(patterns, ascii_case_insensitive, overlapping, leftmost) ) end |
#find(pattern, literal: false, strict: true) ⇒ Expr
To modify regular expression behaviour (such as case-sensitivity) with
flags, use the inline (?iLmsuxU) syntax.
Return the bytes offset of the first substring matching a pattern.
If the pattern is not found, returns nil.
847 848 849 850 |
# File 'lib/polars/string_expr.rb', line 847 def find(pattern, literal: false, strict: true) pattern = Utils.parse_into_expression(pattern, str_as_lit: true) Utils.wrap_expr(_rbexpr.str_find(pattern, literal, strict)) end |
#find_many(patterns, ascii_case_insensitive: false, overlapping: false, leftmost: false) ⇒ Expr
This method supports matching on string literals only, and does not support regular expression matching.
Use the Aho-Corasick algorithm to find many matches.
The function will return the bytes offset of the start of each match.
The return type will be List<UInt32>
1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 |
# File 'lib/polars/string_expr.rb', line 1924 def find_many( patterns, ascii_case_insensitive: false, overlapping: false, leftmost: false ) if overlapping && leftmost msg = "can not match overlapping patterns when leftmost == true" raise ArgumentError, msg end patterns = Utils.parse_into_expression(patterns, str_as_lit: false) Utils.wrap_expr( _rbexpr.str_find_many(patterns, ascii_case_insensitive, overlapping, leftmost) ) end |
#head(n) ⇒ Expr
1) The n input is defined in terms of the number of characters in the (UTF8)
string. A character is defined as a Unicode scalar value. A single
character is represented by a single byte when working with ASCII text, and a
maximum of 4 bytes otherwise.
2) When the n input is negative, head returns characters up to the nth
from the end of the string. For example, if n = -3, then all characters
except the last three are returned.
3) If the length of the string has fewer than n characters, the full string is
returned.
Return the first n characters of each string in a String Series.
1523 1524 1525 1526 |
# File 'lib/polars/string_expr.rb', line 1523 def head(n) n = Utils.parse_into_expression(n) Utils.wrap_expr(_rbexpr.str_head(n)) end |
#join(delimiter = nil, ignore_nulls: true) ⇒ Expr
Vertically concat the values in the Series to a single string value.
381 382 383 384 385 386 387 388 389 |
# File 'lib/polars/string_expr.rb', line 381 def join(delimiter = nil, ignore_nulls: true) # TODO update if delimiter.nil? warn "The default `delimiter` for `join` method will change from `-` to empty string in a future version" delimiter = "-" end Utils.wrap_expr(_rbexpr.str_join(delimiter, ignore_nulls)) end |
#json_decode(dtype, infer_schema_length: nil) ⇒ Expr
Parse string values as JSON.
Throw errors if encounter invalid JSON strings.
960 961 962 963 964 965 966 967 968 |
# File 'lib/polars/string_expr.rb', line 960 def json_decode(dtype, infer_schema_length: nil) if dtype.nil? msg = "`Expr.str.json_decode` needs an explicitly given `dtype` otherwise Polars is not able to determine the output type. If you want to eagerly infer datatype you can use `Series.str.json_decode`." raise TypeError, msg end dtype_expr = Utils.parse_into_datatype_expr(dtype)._rbdatatype_expr Utils.wrap_expr(_rbexpr.str_json_decode(dtype_expr)) end |
#json_path_match(json_path) ⇒ Expr
Extract the first match of json string with provided JSONPath expression.
Throw errors if encounter invalid json strings. All return value will be casted to Utf8 regardless of the original value.
Documentation on JSONPath standard can be found here.
1001 1002 1003 1004 |
# File 'lib/polars/string_expr.rb', line 1001 def json_path_match(json_path) json_path = Utils.parse_into_expression(json_path, str_as_lit: true) Utils.wrap_expr(_rbexpr.str_json_path_match(json_path)) end |
#len_bytes ⇒ Expr
The returned lengths are equal to the number of bytes in the UTF8 string. If you
need the length in terms of the number of characters, use n_chars instead.
Get length of the strings as :u32 (as number of bytes).
311 312 313 |
# File 'lib/polars/string_expr.rb', line 311 def len_bytes Utils.wrap_expr(_rbexpr.str_len_bytes) end |
#len_chars ⇒ Expr
If you know that you are working with ASCII text, lengths will be
equivalent, and faster (returns length in terms of the number of bytes).
Get length of the strings as :u32 (as number of chars).
343 344 345 |
# File 'lib/polars/string_expr.rb', line 343 def len_chars Utils.wrap_expr(_rbexpr.str_len_chars) end |
#normalize(form = "NFC") ⇒ Expr
Returns the Unicode normal form of the string values.
This uses the forms described in Unicode Standard Annex 15: https://www.unicode.org/reports/tr15/.
452 453 454 |
# File 'lib/polars/string_expr.rb', line 452 def normalize(form = "NFC") Utils.wrap_expr(_rbexpr.str_normalize(form)) end |
#pad_end(length, fill_char = " ") ⇒ Expr
Pad the end of the string until it reaches the given length.
713 714 715 716 |
# File 'lib/polars/string_expr.rb', line 713 def pad_end(length, fill_char = " ") length = Utils.parse_into_expression(length) Utils.wrap_expr(_rbexpr.str_pad_end(length, fill_char)) end |
#pad_start(length, fill_char = " ") ⇒ Expr
Pad the start of the string until it reaches the given length.
683 684 685 686 |
# File 'lib/polars/string_expr.rb', line 683 def pad_start(length, fill_char = " ") length = Utils.parse_into_expression(length) Utils.wrap_expr(_rbexpr.str_pad_start(length, fill_char)) end |
#replace(pattern, value, literal: false, n: 1) ⇒ Expr
Replace first matching regex/literal substring with a new string value.
1375 1376 1377 1378 1379 |
# File 'lib/polars/string_expr.rb', line 1375 def replace(pattern, value, literal: false, n: 1) pattern = Utils.parse_into_expression(pattern, str_as_lit: true) value = Utils.parse_into_expression(value, str_as_lit: true) Utils.wrap_expr(_rbexpr.str_replace_n(pattern, value, literal, n)) end |
#replace_all(pattern, value, literal: false) ⇒ Expr
Replace all matching regex/literal substrings with a new string value.
1405 1406 1407 1408 1409 |
# File 'lib/polars/string_expr.rb', line 1405 def replace_all(pattern, value, literal: false) pattern = Utils.parse_into_expression(pattern, str_as_lit: true) value = Utils.parse_into_expression(value, str_as_lit: true) Utils.wrap_expr(_rbexpr.str_replace_all(pattern, value, literal)) end |
#replace_many(patterns, replace_with = NO_DEFAULT, ascii_case_insensitive: false, leftmost: false) ⇒ Expr
Use the aho-corasick algorithm to replace many matches.
1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 |
# File 'lib/polars/string_expr.rb', line 1749 def replace_many( patterns, replace_with = NO_DEFAULT, ascii_case_insensitive: false, leftmost: false ) if replace_with == NO_DEFAULT if !patterns.is_a?(Hash) msg = "`replace_with` argument is required if `patterns` argument is not a Hash type" raise TypeError, msg end # Early return in case of an empty mapping. if patterns.empty? return Utils.wrap_expr(_rbexpr) end replace_with = patterns.values patterns = patterns.keys end patterns = Utils.parse_into_expression(patterns, str_as_lit: false) replace_with = Utils.parse_into_expression(replace_with, str_as_lit: true) Utils.wrap_expr( _rbexpr.str_replace_many( patterns, replace_with, ascii_case_insensitive, leftmost ) ) end |
#reverse ⇒ Expr
Returns string values in reversed order.
1429 1430 1431 |
# File 'lib/polars/string_expr.rb', line 1429 def reverse Utils.wrap_expr(_rbexpr.str_reverse) end |
#slice(offset, length = nil) ⇒ Expr
Create subslices of the string values of a Utf8 Series.
1460 1461 1462 1463 1464 |
# File 'lib/polars/string_expr.rb', line 1460 def slice(offset, length = nil) offset = Utils.parse_into_expression(offset) length = Utils.parse_into_expression(length) Utils.wrap_expr(_rbexpr.str_slice(offset, length)) end |
#split(by, inclusive: false, literal: true, strict: true) ⇒ Expr
Split the string by a substring.
1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 |
# File 'lib/polars/string_expr.rb', line 1253 def split(by, inclusive: false, literal: true, strict: true) by_rbexpr = Utils.parse_into_expression(by, str_as_lit: true) if !literal if inclusive return Utils.wrap_expr( _rbexpr.str_split_regex_inclusive(by_rbexpr, strict) ) end return Utils.wrap_expr(_rbexpr.str_split_regex(by_rbexpr, strict)) end if inclusive return Utils.wrap_expr(_rbexpr.str_split_inclusive(by_rbexpr)) end Utils.wrap_expr(_rbexpr.str_split(by_rbexpr)) end |
#split_exact(by, n, inclusive: false) ⇒ Expr
Split the string by a substring using n splits.
Results in a struct of n+1 fields.
If it cannot make n splits, the remaining field elements will be null.
1305 1306 1307 1308 1309 1310 1311 1312 |
# File 'lib/polars/string_expr.rb', line 1305 def split_exact(by, n, inclusive: false) by = Utils.parse_into_expression(by, str_as_lit: true) if inclusive Utils.wrap_expr(_rbexpr.str_split_exact_inclusive(by, n)) else Utils.wrap_expr(_rbexpr.str_split_exact(by, n)) end end |
#splitn(by, n) ⇒ Expr
Split the string by a substring, restricted to returning at most n items.
If the number of possible splits is less than n-1, the remaining field
elements will be null. If the number of possible splits is n-1 or greater,
the last (nth) substring will contain the remainder of the string.
1342 1343 1344 1345 |
# File 'lib/polars/string_expr.rb', line 1342 def splitn(by, n) by = Utils.parse_into_expression(by, str_as_lit: true) Utils.wrap_expr(_rbexpr.str_splitn(by, n)) end |
#starts_with(prefix) ⇒ Expr
Check if string values start with a substring.
927 928 929 930 |
# File 'lib/polars/string_expr.rb', line 927 def starts_with(prefix) prefix_rbexpr = Utils.parse_into_expression(prefix, str_as_lit: true) Utils.wrap_expr(_rbexpr.str_starts_with(prefix_rbexpr)) end |
#strip_chars(characters = nil) ⇒ Expr
Remove leading and trailing whitespace.
542 543 544 545 |
# File 'lib/polars/string_expr.rb', line 542 def strip_chars(characters = nil) characters = Utils.parse_into_expression(characters, str_as_lit: true) Utils.wrap_expr(_rbexpr.str_strip_chars(characters)) end |
#strip_chars_end(characters = nil) ⇒ Expr
Remove trailing whitespace.
594 595 596 597 |
# File 'lib/polars/string_expr.rb', line 594 def strip_chars_end(characters = nil) characters = Utils.parse_into_expression(characters, str_as_lit: true) Utils.wrap_expr(_rbexpr.str_strip_chars_end(characters)) end |
#strip_chars_start(characters = nil) ⇒ Expr
Remove leading whitespace.
568 569 570 571 |
# File 'lib/polars/string_expr.rb', line 568 def strip_chars_start(characters = nil) characters = Utils.parse_into_expression(characters, str_as_lit: true) Utils.wrap_expr(_rbexpr.str_strip_chars_start(characters)) end |
#strip_prefix(prefix) ⇒ Expr
Remove prefix.
The prefix will be removed from the string exactly once, if found.
623 624 625 626 |
# File 'lib/polars/string_expr.rb', line 623 def strip_prefix(prefix) prefix = Utils.parse_into_expression(prefix, str_as_lit: true) Utils.wrap_expr(_rbexpr.str_strip_prefix(prefix)) end |
#strip_suffix(suffix) ⇒ Expr
Remove suffix.
The suffix will be removed from the string exactly once, if found.
653 654 655 656 |
# File 'lib/polars/string_expr.rb', line 653 def strip_suffix(suffix) suffix = Utils.parse_into_expression(suffix, str_as_lit: true) Utils.wrap_expr(_rbexpr.str_strip_suffix(suffix)) end |
#strptime(dtype, format = nil, strict: true, exact: true, cache: true, ambiguous: "raise") ⇒ Expr
When parsing a Datetime the column precision will be inferred from the format string, if given, eg: "%F %T%.3f" => Datetime("ms"). If no fractional second component is found then the default is "us".
Parse a Utf8 expression to a Date/Datetime/Time type.
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/polars/string_expr.rb', line 210 def strptime( dtype, format = nil, strict: true, exact: true, cache: true, ambiguous: "raise" ) _validate_format_argument(format) if dtype == Date to_date(format, strict: strict, exact: exact, cache: cache) elsif dtype == Datetime || dtype.is_a?(Datetime) dtype = Datetime.new if dtype == Datetime time_unit = dtype.time_unit time_zone = dtype.time_zone to_datetime( format, time_unit: time_unit, time_zone: time_zone, strict: strict, exact: exact, cache: cache, ambiguous: ambiguous ) elsif dtype == Time to_time(format, strict: strict, cache: cache) else raise ArgumentError, "dtype should be of type {Date, Datetime, Time}" end end |
#tail(n) ⇒ Expr
1) The n input is defined in terms of the number of characters in the (UTF8)
string. A character is defined as a Unicode scalar value. A single
character is represented by a single byte when working with ASCII text, and a
maximum of 4 bytes otherwise.
2) When the n input is negative, tail returns characters starting from the
nth from the beginning of the string. For example, if n = -3, then all
characters except the first three are returned.
3) If the length of the string has fewer than n characters, the full string is
returned.
Return the last n characters of each string in a String Series.
1585 1586 1587 1588 |
# File 'lib/polars/string_expr.rb', line 1585 def tail(n) n = Utils.parse_into_expression(n) Utils.wrap_expr(_rbexpr.str_tail(n)) end |
#to_date(format = nil, strict: true, exact: true, cache: true) ⇒ Expr
Convert a Utf8 column into a Date column.
40 41 42 43 |
# File 'lib/polars/string_expr.rb', line 40 def to_date(format = nil, strict: true, exact: true, cache: true) _validate_format_argument(format) Utils.wrap_expr(_rbexpr.str_to_date(format, strict, exact, cache)) end |
#to_datetime(format = nil, time_unit: nil, time_zone: nil, strict: true, exact: true, cache: true, ambiguous: "raise") ⇒ Expr
Convert a Utf8 column into a Datetime column.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/polars/string_expr.rb', line 86 def to_datetime( format = nil, time_unit: nil, time_zone: nil, strict: true, exact: true, cache: true, ambiguous: "raise" ) _validate_format_argument(format) unless ambiguous.is_a?(Expr) ambiguous = Polars.lit(ambiguous) end Utils.wrap_expr( _rbexpr.str_to_datetime( format, time_unit, time_zone, strict, exact, cache, ambiguous._rbexpr ) ) end |
#to_decimal(scale:) ⇒ Expr
Convert a String column into a Decimal column.
279 280 281 |
# File 'lib/polars/string_expr.rb', line 279 def to_decimal(scale:) Utils.wrap_expr(_rbexpr.str_to_decimal(scale)) end |
#to_integer(base: 10, dtype: Int64, strict: true) ⇒ Expr
Convert an Utf8 column into an Int64 column with base radix.
1632 1633 1634 1635 |
# File 'lib/polars/string_expr.rb', line 1632 def to_integer(base: 10, dtype: Int64, strict: true) base = Utils.parse_into_expression(base, str_as_lit: false) Utils.wrap_expr(_rbexpr.str_to_integer(base, dtype, strict)) end |
#to_lowercase ⇒ Expr
Transform to lowercase variant.
494 495 496 |
# File 'lib/polars/string_expr.rb', line 494 def to_lowercase Utils.wrap_expr(_rbexpr.str_to_lowercase) end |
#to_time(format = nil, strict: true, cache: true) ⇒ Expr
Convert a Utf8 column into a Time column.
137 138 139 140 |
# File 'lib/polars/string_expr.rb', line 137 def to_time(format = nil, strict: true, cache: true) _validate_format_argument(format) Utils.wrap_expr(_rbexpr.str_to_time(format, strict, cache)) end |
#to_titlecase ⇒ Expr
Transform to titlecase variant.
517 518 519 |
# File 'lib/polars/string_expr.rb', line 517 def to_titlecase Utils.wrap_expr(_rbexpr.str_to_titlecase) end |
#to_uppercase ⇒ Expr
Transform to uppercase variant.
473 474 475 |
# File 'lib/polars/string_expr.rb', line 473 def to_uppercase Utils.wrap_expr(_rbexpr.str_to_uppercase) end |
#zfill(length) ⇒ Expr
Fills the string with zeroes.
Return a copy of the string left filled with ASCII '0' digits to make a string of length width.
A leading sign prefix ('+'/'-') is handled by inserting the padding after the
sign character rather than before. The original string is returned if width is
less than or equal to s.length.
747 748 749 750 |
# File 'lib/polars/string_expr.rb', line 747 def zfill(length) length = Utils.parse_into_expression(length) Utils.wrap_expr(_rbexpr.str_zfill(length)) end |