datetime
DatetimeTransformer
Bases: TransformerWrapper
A transformer to convert datetime features to numeric features. Before applying an underlying (wrapped) transformer.
The datetime features are converted to nanoseconds since the epoch, and missing values are assigned to 0.0 under the AugmentMissingnessStrategy
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transformer |
ColumnTransformer
|
The |
required |
After applying the transformer, the following attributes will be populated:
Attributes:
Name | Type | Description |
---|---|---|
original_column_name |
The name of the original column. |
Source code in src/nhssynth/modules/dataloader/transformers/datetime.py
apply(data, missingness_column=None, **kwargs)
Firstly, the datetime data is floored to the nano-second level. Next, the floored data is converted to float nanoseconds since the epoch.
The float value of pd.NaT
under the operation above is then replaced with np.nan
to ensure missing values are represented correctly.
Finally, the wrapped transformer is applied to the data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Series
|
The column of data to transform. |
required |
missingness_column |
Optional[Series]
|
The column of missingness indicators to augment the data with. |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
The transformed data. |
Source code in src/nhssynth/modules/dataloader/transformers/datetime.py
revert(data, **kwargs)
The wrapped transformer's revert
method is applied to the data. The data is then converted back to datetime format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
DataFrame
|
The full dataset including the column(s) to be reverted to their pre-transformer state. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
The reverted data. |