Skip to content

transformers

sorix.preprocessing.transformers

ColumnTransformer

ColumnTransformer(transformers)
Source code in sorix/preprocessing/transformers.py
4
5
6
7
def __init__(self, transformers: list[tuple]):
    self.transformers = transformers
    self.n_features = 0
    self.features_names = []

state_dict

state_dict()

Returns a dictionary with the state of the column transformer.

Source code in sorix/preprocessing/transformers.py
def state_dict(self):
    """Returns a dictionary with the state of the column transformer."""
    state = {
        'n_features': self.n_features,
        'features_names': self.features_names,
        'transformers_states': []
    }
    for name, tf, cols in self.transformers:
        if hasattr(tf, 'state_dict') and callable(tf.state_dict):
            state['transformers_states'].append((name, tf.state_dict(), cols))
        else:
            # Fallback if the transformer doesn't have state_dict (unlikely in sorix)
            state['transformers_states'].append((name, tf, cols))
    return state

load_state_dict

load_state_dict(state_dict)

Loads the state of the column transformer.

Source code in sorix/preprocessing/transformers.py
def load_state_dict(self, state_dict):
    """Loads the state of the column transformer."""
    self.n_features = state_dict['n_features']
    self.features_names = state_dict['features_names']

    # Mapping for easier lookup
    tf_states = {name: (state, cols) for name, state, cols in state_dict['transformers_states']}

    for name, tf, cols in self.transformers:
        if name in tf_states:
            state, _ = tf_states[name]
            if hasattr(tf, 'load_state_dict') and callable(tf.load_state_dict):
                tf.load_state_dict(state)
            else:
                # If it was saved as the object itself
                # (this might happen if tf didn't have state_dict when saved)
                # But in our new system they will have it.
                pass
    return self