Skip to content

String Expressions

All string operations are valid for both scalars and columns.

strings

Classes

StringValue (Value)

Methods
ascii_str(self)

Return the numeric ASCII code of the first character of a string.

Returns

IntegerValue ASCII code of the first character of the input

capitalize(self)

Capitalize the input string.

Returns

StringValue Capitalized string

concat(self, other, *args)

Concatenate strings.

Parameters

other String to concatenate args Additional strings to concatenate

Returns

StringValue All strings concatenated

contains(self, substr)

Return whether the expression contains substr.

Parameters

substr Substring for which to check

Returns

BooleanValue Boolean indicating the presence of substr in the expression

convert_base(self, from_base, to_base)

Convert a string representing an integer from one base to another.

Parameters

from_base Numeric base of the expression to_base New base

Returns

IntegerValue Converted expression

endswith(self, end)

Determine if self ends with end.

Parameters

end Suffix to check for

Examples

import ibis text = ibis.literal('Ibis project') text.endswith('project') EndsWith('Ibis project', end='project')

Returns

BooleanValue Boolean indicating whether self ends with end

find(self, substr, start=None, end=None)

Return the position of the first occurence of substring.

Parameters

substr Substring to search for start Zero based index of where to start the search end Zero based index of where to stop the search. Currently not implemented.

Returns

IntegerValue Position of substr in arg starting from start

find_in_set(self, str_list)

Find the first occurence of str_list within a list of strings.

No string in str_list can have a comma.

Parameters

str_list Sequence of strings

Examples

import ibis table = ibis.table([('strings', 'string')]) result = table.strings.find_in_set(['a', 'b'])

Returns

IntegerValue Position of str_list in self. Returns -1 if self isn't found or if self contains ','.

hashbytes(self, how='sha256')

Compute the binary hash value of the input.

Parameters

how Hash algorithm to use

Returns

BinaryValue Binary expression

ilike(self, patterns)

Match patterns against self, case-insensitive.

This function is modeled after SQL's ILIKE directive. Use % as a multiple-character wildcard or _ as a single-character wildcard.

Use re_search or rlike for regular expression-based matching.

Parameters

patterns If pattern is a list, then if any pattern matches the input then the corresponding row in the output is True.

Returns

BooleanValue Column indicating matches

initcap(self)

Capitalize the input string.

Returns

StringValue Capitalized string

join(self, strings)

Join a list of strings using self as the separator.

Parameters

self String expression strings Strings to join with arg

Examples

import ibis sep = ibis.literal(',') result = sep.join(['a', 'b', 'c'])

Returns

StringValue Joined string

left(self, nchars)

Return the nchars left-most characters.

Parameters

nchars Maximum number of characters to return

Returns

StringValue Characters from the start

length(self)

Compute the length of a string.

Returns

IntegerValue The length of the input

like(self, patterns)

Match patterns against self, case-sensitive.

This function is modeled after the SQL LIKE directive. Use % as a multiple-character wildcard or _ as a single-character wildcard.

Use re_search or rlike for regular expression-based matching.

Parameters

patterns If pattern is a list, then if any pattern matches the input then the corresponding row in the output is True.

Returns

BooleanValue Column indicating matches

lower(self)

Convert string to all lowercase.

Returns

StringValue Lowercase string

lpad(self, length, pad=' ')

Pad arg by truncating on the right or padding on the left.

Parameters

length Length of output string pad Pad character

Examples

import ibis table = ibis.table([('strings', 'string')]) expr = table.strings.lpad(5, '-') expr = ibis.literal('a').lpad(5, '-') # 'a' becomes '----a' expr = ibis.literal('abcdefg').lpad(5, '-') # 'abcdefg' becomes 'abcde' # noqa: E501

Returns

StringValue Padded string

lstrip(self)

Remove whitespace from the left side of string.

Returns

StringValue Left-stripped string

parse_url(self, extract, key=None)

Parse a URL and extract its components.

key can be used to extract query values when extract == 'QUERY'

Parameters

extract Component of URL to extract key Query component to extract

Examples

url = "https://www.youtube.com/watch?v=kEuEcWfewf8&t=10" parse_url(url, 'QUERY', 'v') # doctest: +SKIP 'kEuEcWfewf8'

Returns

StringValue Extracted string value

re_extract(self, pattern, index)

Return the specified match at index from a regex pattern.

Parameters

pattern Reguar expression string index Zero-based index of match to return

Returns

StringValue Extracted match

re_replace(self, pattern, replacement)

Replace match found by regex pattern with replacement.

Parameters

pattern Regular expression string replacement Replacement string or regular expression

Examples

import ibis table = ibis.table([('strings', 'string')]) result = table.strings.replace('(b+)', r'<>') # 'aaabbbaa' becomes 'aaaaaa' # noqa: E501

Returns

StringValue Modified string

Return whether the values match pattern.

Returns True if the regex matches a string and False otherwise.

Parameters

pattern Regular expression use for searching

Returns

BooleanValue Indicator of matches

repeat(self, n)

Repeat a string n times.

Parameters

n Number of repetitions

Returns

StringValue Repeated string

replace(self, pattern, replacement)

Replace each exact match of pattern with replacement.

Parameters

pattern String pattern replacement String replacement

Examples

import ibis table = ibis.table([('strings', 'string')]) result = table.strings.replace('aaa', 'foo') # 'aaabbbaaa' becomes 'foobbbfoo' # noqa: E501

Returns

StringVulae Replaced string

reverse(self)

Reverse the characters of a string.

Returns

StringValue Reversed string

right(self, nchars)

Return up to nchars from the end of each string.

Parameters

nchars Maximum number of characters to return

Returns

StringValue Characters from the end

rlike(self, pattern)

Return whether the values match pattern.

Returns True if the regex matches a string and False otherwise.

Parameters

pattern Regular expression use for searching

Returns

BooleanValue Indicator of matches

rpad(self, length, pad=' ')

Pad self by truncating or padding on the right.

Parameters

self String to pad length Length of output string pad Pad character

Examples

import ibis table = ibis.table([('string_col', 'string')]) expr = table.string_col.rpad(5, '-') expr = ibis.literal('a').rpad(5, '-') # 'a' becomes 'a----' expr = ibis.literal('abcdefg').rpad(5, '-') # 'abcdefg' becomes 'abcde' # noqa: E501

Returns

StringValue Padded string

rstrip(self)

Remove whitespace from the right side of string.

Returns

StringValue Right-stripped string

split(self, delimiter)

Split as string on delimiter.

Parameters

delimiter Value to split by

Returns

ArrayValue The string split by delimiter

startswith(self, start)

Determine whether self starts with end.

Parameters

start prefix to check for

Examples

import ibis text = ibis.literal('Ibis project') text.startswith('Ibis') StartsWith('Ibis project', start='Ibis')

Returns

BooleanValue Boolean indicating whether self starts with start

strip(self)

Remove whitespace from left and right sides of a string.

Returns

StringValue Stripped string

substr(self, start, length=None)

Extract a substring.

Parameters

start First character to start splitting, indices start at 0 length Maximum length of each substring. If not supplied, searches the entire string

Returns

StringValue Found substring

to_timestamp(self, format_str, timezone=None)

Parse a string and return a timestamp.

Parameters

format_str Format string in strptime format timezone A string indicating the timezone. For example 'America/New_York'

Examples

import ibis date_as_str = ibis.literal('20170206') result = date_as_str.to_timestamp('%Y%m%d')

Returns

TimestampValue Parsed timestamp value

translate(self, from_str, to_str)

Replace from_str characters in self characters in to_str.

To avoid unexpected behavior, from_str should be shorter than to_str.

Parameters

from_str Characters in arg to replace to_str Characters to use for replacement

Examples

import ibis table = ibis.table([('string_col', 'string')]) expr = table.string_col.translate('a', 'b') expr = table.string_col.translate('a', 'bc')

Returns

StringValue Translated string

upper(self)

Convert string to all uppercase.

Returns

StringValue Uppercase string


Last update: February 3, 2022