Skip to content

Commit

Permalink
better docstring and test
Browse files Browse the repository at this point in the history
  • Loading branch information
cademack committed Jan 9, 2024
1 parent f438b17 commit 4594e27
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ def infer_feature_attributes(data: Union[pd.DataFrame, SQLRelationalDatastorePro
If True, the time feature will be treated as universal and future data
is excluded while making predictions. If False, the time feature will
not be treated as universal and only future data within the same series
is excluded while making predictions.
is excluded while making predictions. It is recommended to set this
value to True if there is any possibility of global relevancy of time,
which is the default behavior.
time_series_type_default : str, default 'rate'
(Optional) Type specifying how time series is generated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,32 @@ def test_set_rate_delta_boundaries():
assert 'rate_max' not in features['date']['time_series']
assert 'delta_min' not in features['f3']['time_series']
assert 'delta_max' not in features['f3']['time_series']


@pytest.mark.parametrize(
("universal_value", "expected"),
[
(True, True),
(False, False),
(None, None),
]
)
def test_time_feature_is_universal(universal_value, expected):
"""Validates that time_feature_is_universal is working as expected."""
df = pd.read_csv(data_path)

# Define time format
time_format = "%Y%m%d"
# Identify id-feature and time-feature
id_feature_name = "ID"
time_feature_name = "date"

features = infer_feature_attributes(
df,
time_feature_name=time_feature_name,
id_feature_name=id_feature_name,
datetime_feature_formats={time_feature_name: time_format},
time_feature_is_universal=universal_value,
)

assert features[time_feature_name]['time_series'].get("universal") == expected
4 changes: 3 additions & 1 deletion howso/utilities/feature_attributes/time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,9 @@ def _process( # noqa: C901
If True, the time feature will be treated as universal and future data
is excluded while making predictions. If False, the time feature will
not be treated as universal and only future data within the same series
is excluded while making predictions.
is excluded while making predictions. It is recommended to set this
value to True if there is any possibility of global relevancy of time,
which is the default behavior.
time_series_type_default : str, default 'rate'
(Optional) Type specifying how time series is generated.
Expand Down

0 comments on commit 4594e27

Please sign in to comment.