id_translation.dio.integration.polars#

Integration for Polars types.

Module Attributes

PolarsT

Supported polars types.

Classes

PolarsIO(*[, fast])

Optional IO implementation for polars types.

class PolarsIO(*, fast=False)[source]#

Bases: DataStructureIO[PolarsT, str, SourceType, IdType]

Optional IO implementation for polars types.

Parameters:

fast – Apply optimizations if True. Can be faster for large amounts of data but is much less flexible.

classmethod extract(translatable, names)[source]#

Extract IDs from translatable.

Parameters:
  • translatable – Data to extract IDs from.

  • names – List of names in translatable to extract IDs for.

Returns:

A dict {name: ids}.

classmethod handles_type(arg)[source]#

Return True if the implementation handles data for the type of arg.

insert(translatable, names, tmap, copy)[source]#

Insert translations into translatable.

Parameters:
  • translatable – Data to translate. Modified iff copy=False.

  • names – Names in translatable to translate.

  • tmap – Translations for IDs in translatable.

  • copy – If True, modify contents of the original translatable. Otherwise, returns a copy.

Returns:

A copy of translatable if copy=True, None otherwise.

Raises:

NotInplaceTranslatableError – If copy=False for a type which is not translatable in-place.

classmethod names(translatable)[source]#

Extract names from translatable.

Parameters:

translatable – Data to extract names from.

Returns:

A list of names to translate. Returns None if names cannot be extracted.

static obj_to_str(series)[source]#

Utility method for dtype conversion.

Will cast polars.Object to polars.String, which is slow but required for translation. Elements are mapped using the regular builtin str function.

This method is never called when fast=True.

Returns:

A series which does not use the polars.Object dtype. No changes are made if any other dtype is used.

priority = 1990#

Determines order in which IOs are considered (higher = earlier).

Set priority < 0 to disable.

class PolarsT#

Supported polars types.

alias of TypeVar(‘PolarsT’, ~polars.dataframe.frame.DataFrame, ~polars.series.series.Series)