MergeConsecutiveOp

class MergeConsecutiveOp(parameters)[source]

Merge consecutive rows with same column value.

Required remodeling parameters:
  • column_name (str): name of column whose consecutive values are to be compared (the merge column).

  • event_code (str or int or float): the particular value in the match column to be merged.

  • match_columns (list): A list of columns whose values have to be matched for two events to be the same.

  • set_durations (bool): If true, set the duration of the merged event to the extent of the merged events.

  • ignore_missing (bool): If true, missing match_columns are ignored.

Methods

hed.tools.remodeling.operations.merge_consecutive_op.MergeConsecutiveOp.__init__(...)

Constructor for the merge consecutive operation.

hed.tools.remodeling.operations.merge_consecutive_op.MergeConsecutiveOp.check_parameters(...)

Verify that the parameters meet the operation specification.

hed.tools.remodeling.operations.merge_consecutive_op.MergeConsecutiveOp.do_op(...)

Merge consecutive rows with the same column value.

Attributes

hed.tools.remodeling.operations.merge_consecutive_op.MergeConsecutiveOp.PARAMS

MergeConsecutiveOp.__init__(parameters)[source]

Constructor for the merge consecutive operation.

Parameters:

parameters (dict) – Actual values of the parameters for the operation.

Raises:
  • KeyError

    • If a required parameter is missing.

    • If an unexpected parameter is provided.

  • TypeError

    • If a parameter has the wrong type.

  • ValueError

    • If the specification is missing a valid operation.

    • If one of the match column is the merge column.

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

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

Merge consecutive rows with the same column value.

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 dataframe does not have the anchor column and ignore_missing is False.

  • If a match column is missing and ignore_missing is false.

  • If the durations were to be set and the dataframe did not have an onset column.

  • If the durations were to be set and the dataframe did not have a duration column.

MergeConsecutiveOp.PARAMS = {'operation': 'merge_consecutive', 'optional_parameters': {}, 'required_parameters': {'column_name': <class 'str'>, 'event_code': [<class 'str'>, <class 'int'>, <class 'float'>], 'ignore_missing': <class 'bool'>, 'match_columns': <class 'list'>, 'set_durations': <class 'bool'>}}