RenameColumnsOp

class RenameColumnsOp(parameters)[source]

Rename columns in a tabular file.

Required remodeling parameters:
  • column_mapping (dict): The names of the columns to be removed.

  • ignore_missing (bool): If true, the names in column_mapping that are not columns and should be ignored.

Methods

hed.tools.remodeling.operations.rename_columns_op.RenameColumnsOp.__init__(...)

Constructor for rename columns operation.

hed.tools.remodeling.operations.rename_columns_op.RenameColumnsOp.check_parameters(...)

Verify that the parameters meet the operation specification.

hed.tools.remodeling.operations.rename_columns_op.RenameColumnsOp.do_op(...)

Rename columns as specified in column_mapping dictionary.

Attributes

hed.tools.remodeling.operations.rename_columns_op.RenameColumnsOp.PARAMS

RenameColumnsOp.__init__(parameters)[source]

Constructor for rename columns operation.

Parameters:

parameters (dict) – Dictionary with the 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.

RenameColumnsOp.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.

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

Rename columns as specified in column_mapping dictionary.

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:

KeyError

  • When ignore_missing is false and column_mapping has columns not in the data.

RenameColumnsOp.PARAMS = {'operation': 'rename_columns', 'optional_parameters': {}, 'required_parameters': {'column_mapping': <class 'dict'>, 'ignore_missing': <class 'bool'>}}