RemapColumnsOp

class RemapColumnsOp(parameters)[source]

Map values in m columns into a new combinations in n columns.

Required remodeling parameters:
  • source_columns (list): The key columns to map (m key columns).

  • destination_columns (list): The destination columns to have the mapped values (n destination columns).

  • map_list (list): A list of lists with the mapping.

  • ignore_missing (bool): If True, entries whose key column values are not in map_list are ignored.

Optional remodeling parameters:

integer_sources (list): Source columns that should be treated as integers rather than strings.

Notes

Each list element list is of length m + n with the key columns followed by mapped columns.

TODO: Allow wildcards

Methods

hed.tools.remodeling.operations.remap_columns_op.RemapColumnsOp.__init__(...)

Constructor for the remap columns operation.

hed.tools.remodeling.operations.remap_columns_op.RemapColumnsOp.check_parameters(...)

Verify that the parameters meet the operation specification.

hed.tools.remodeling.operations.remap_columns_op.RemapColumnsOp.do_op(...)

Remap new columns from combinations of others.

Attributes

hed.tools.remodeling.operations.remap_columns_op.RemapColumnsOp.PARAMS

RemapColumnsOp.__init__(parameters)[source]

Constructor for the remap columns operation.

Parameters:

parameters (dict) – Parameter values for required and optional parameters.

Raises:
  • KeyError

    • If a required parameter is missing.

    • If an unexpected parameter is provided.

  • TypeError

    • If a parameter has the wrong type.

  • ValueError

    • If an integer column is not a key column.

    • If a column designated as an integer source does not have valid integers.

    • If no source columns are specified.

    • If no destination columns are specified.

    • If a map_list entry has the wrong number of items (source columns + destination columns).

RemapColumnsOp.check_parameters(parameters)

Verify that the parameters meet the operation specification.

Parameters:

parameters (dict) – Dictionary of parameters for this operation.

Raises:
  • KeyError

    • If a required parameter is missing.

    • If an unexpected parameter is provided.

  • TypeError

    • If a parameter has the wrong type.

RemapColumnsOp.do_op(dispatcher, df, name, sidecar=None)[source]

Remap new columns from combinations of others.

Parameters:
  • dispatcher (Dispatcher) – Manages the operation I/O.

  • df (DataFrame) – The DataFrame to be remodeled.

  • name (str) – Unique identifier for the dataframe – often the original file path.

  • sidecar (Sidecar or file-like) – Not needed for this operation.

Returns:

A new dataframe after processing.

Return type:

Dataframe

Raises:

ValueError

  • If ignore_missing is false and source values from the data are not in the map.

RemapColumnsOp.PARAMS = {'operation': 'remap_columns', 'optional_parameters': {'integer_sources': <class 'list'>}, 'required_parameters': {'destination_columns': <class 'list'>, 'ignore_missing': <class 'bool'>, 'map_list': <class 'list'>, 'source_columns': <class 'list'>}}