Skip to content

Commit

Permalink
changed defaults and added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gsheni committed Feb 11, 2025
1 parent d1f8732 commit 9909c90
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
10 changes: 5 additions & 5 deletions rdt/transformers/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class UnixTimestampEncoder(BaseTransformer):
Indicate what to replace the null values with. If the strings ``'mean'`` or ``'mode'``
are given, replace them with the corresponding aggregation, if ``'random'``, use
random values from the dataset to fill the nan values.
Defaults to ``mean``.
Defaults to ``random``.
model_missing_values (bool):
**DEPRECATED** Whether to create a new column to indicate which values were null or
not. The column will be created only if there are null values. If ``True``, create
Expand Down Expand Up @@ -53,14 +53,14 @@ class UnixTimestampEncoder(BaseTransformer):

def __init__(
self,
missing_value_replacement='mean',
missing_value_replacement='random',
model_missing_values=None,
datetime_format=None,
missing_value_generation='random',
enforce_min_max_values=False,
):
super().__init__()
self._set_missing_value_replacement('mean', missing_value_replacement)
self._set_missing_value_replacement('random', missing_value_replacement)
self._set_missing_value_generation(missing_value_generation)
self.enforce_min_max_values = enforce_min_max_values
if model_missing_values is not None:
Expand Down Expand Up @@ -248,7 +248,7 @@ class OptimizedTimestampEncoder(UnixTimestampEncoder):
Indicate what to replace the null values with. If the strings ``'mean'`` or ``'mode'``
are given, replace them with the corresponding aggregation, if ``'random'``, use
random values from the dataset to fill the nan values.
Defaults to ``mean``.
Defaults to ``random``.
model_missing_values (bool):
**DEPRECATED** Whether to create a new column to indicate which values were null or
not. The column will be created only if there are null values. If ``True``, create
Expand All @@ -275,7 +275,7 @@ class OptimizedTimestampEncoder(UnixTimestampEncoder):

def __init__(
self,
missing_value_replacement=None,
missing_value_replacement='random',
model_missing_values=None,
datetime_format=None,
missing_value_generation='random',
Expand Down
18 changes: 17 additions & 1 deletion tests/unit/transformers/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def test___init__with_model_missing_values(self):
assert transformer.missing_value_generation == 'random'
assert transformer.datetime_format == '%M-%d-%Y'

def test_default_missing_value_replacement(self):
"""Test the default value of missing_value_replacement is 'random'"""
# Run
transformer = UnixTimestampEncoder()

# Assert
assert transformer.missing_value_replacement == 'random'

def test__convert_to_datetime(self):
"""Test the ``_convert_to_datetime`` method.
Expand Down Expand Up @@ -270,7 +278,7 @@ def test__fit(self, null_transformer_mock):
"""
# Setup
data = pd.to_datetime(['2020-01-01', '2020-02-01', '2020-03-01'])
transformer = UnixTimestampEncoder()
transformer = UnixTimestampEncoder(missing_value_replacement='mean')

# Run
transformer._fit(data)
Expand Down Expand Up @@ -604,6 +612,14 @@ def test___init__(self):
assert transformer.divider is None
assert transformer.null_transformer is None

def test_default_missing_value_replacement(self):
"""Test the default value of missing_value_replacement is 'random'"""
# Run
transformer = OptimizedTimestampEncoder()

# Assert
assert transformer.missing_value_replacement == 'random'

def test__find_divider(self):
"""Test the ``_find_divider`` method.
Expand Down

0 comments on commit 9909c90

Please sign in to comment.