tidypolars_extra.type_conversion

Functions

as_boolean(x)

Convert column to string. Alias to as_logical (R naming).

as_categorical(*args, **kwargs)

Convert to factor. Alias for as_factor

as_character(x)

Convert to string. Defaults to Utf8.

as_factor(x[, levels])

Convert to factor (R naming), equlivalent to Enum or

as_float(x)

Convert to float. Defaults to Float64.

as_integer(x)

Convert to integer. Defaults to Int64.

as_logical(x)

Convert to a boolean (polars) or 'logical' (R naming)

as_string(x)

Convert column to string. Alias to as_character (R naming).

cast(x, dtype)

General type conversion.

Module Contents

tidypolars_extra.type_conversion.as_boolean(x)[source]

Convert column to string. Alias to as_logical (R naming).

tidypolars_extra.type_conversion.as_categorical(*args, **kwargs)[source]

Convert to factor. Alias for as_factor

tidypolars_extra.type_conversion.as_character(x)[source]

Convert to string. Defaults to Utf8.

Parameters:

x (Str) – Column to operate on

Examples

>>> df.mutate(string_x = tp.as_string('x'))
# or equivalently
>>> df.mutate(character_x = tp.as_character('x'))
tidypolars_extra.type_conversion.as_factor(x, levels=None)[source]

Convert to factor (R naming), equlivalent to Enum or Categorical (polars), depending on whether ‘levels’ is provided.

Parameters:
  • x (Str) – Column to operate on

  • levels (list of str) – Categories to use in the factor. The catogories will be ordered as they appear in the list. If None (default), it will create an unordered factor (polars Categorical).

Examples

>>> df.mutate(factor_x = tp.as_factor('x'))
# or equivalently
>>> df.mutate(categorical_x = tp.as_categorical('x'))
tidypolars_extra.type_conversion.as_float(x)[source]

Convert to float. Defaults to Float64.

Parameters:

x (Expr, Series) – Column to operate on

Examples

>>> df.mutate(float_x = tp.as_float(col('x')))
tidypolars_extra.type_conversion.as_integer(x)[source]

Convert to integer. Defaults to Int64.

Parameters:

x (Expr) – Column to operate on

Examples

>>> df.mutate(int_x = tp.as_integer(col('x')))
tidypolars_extra.type_conversion.as_logical(x)[source]

Convert to a boolean (polars) or ‘logical’ (R naming)

Parameters:

x (Str) – Column to operate on

Examples

>>> df.mutate(bool_x = tp.as_boolean(col('x')))
# or equivalently
>>> df.mutate(logical_x = tp.as_logical(col('x')))
tidypolars_extra.type_conversion.as_string(x)[source]

Convert column to string. Alias to as_character (R naming). Equivalent to Utf8 type (polars)

tidypolars_extra.type_conversion.cast(x, dtype)[source]

General type conversion.

Parameters:
  • x (Expr, Series) – Column to operate on

  • dtype (DataType) – Type to convert to

Examples

>>> df.mutate(abs_x = tp.cast(col('x'), tp.Float64))