Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numerical & datetime transformers crash if the entire column is null #637

Closed
npatki opened this issue Apr 25, 2023 · 0 comments · Fixed by #640
Closed

Numerical & datetime transformers crash if the entire column is null #637

npatki opened this issue Apr 25, 2023 · 0 comments · Fixed by #640
Assignees
Labels
bug Something isn't working
Milestone

Comments

@npatki
Copy link
Contributor

npatki commented Apr 25, 2023

  • RDT version: 1.4.1 (latest)

Error Description

Sometimes, I may have a numerical or datetime column that is entirely null. This can happen for a number of reasons - eg. I may only have access to a subset of data for training and it just happens to be all null.

Currently, the numerical and datetime transformers crash if they encounter this. Instead, we can gracefully fall back and allow the remaining flow to proceed.

Steps to reproduce

Reproduce this by creating data with all null values. Note that this is replicable for both datetime and numerical sdtypes.

import pandas as pd
import numpy as np
from rdt import HyperTransformer
from rdt.transformers.datetime import UnixTimestampEncoder

data = pd.DataFrame(data={
  'null_datetime_column': ['']*5,
  'null_numerical_column': [np.nan]*5
})

ht = HyperTransformer()
ht.detect_initial_config(data=data)

ht.update_sdtypes({ 'null_datetime_column': 'datetime' })
ht.update_transformers({ 'null_datetime_column': UnixTimestampEncoder(datetime_format='%Y-%m-%d') })
ht.fit(data)

Output:

TransformerInputError: 'missing_value_replacement' cannot be set to 'mean' when the provided data
only contains NaNs.

Fix

If the entire column is null, then use some pre-determined values as the missing value replacement

  • For numerical, we can use 0
  • For datetime, we can use the Unix equivalent of 0: January 1st, 1970 at UTC

Then we can convert the TransformerInputError into an logger.INFO message insetad:

logger.INFO: 'missing_value_replacement' cannot be set to 'mean' when the provided data
only contains NaNs. Using 0 instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants