Skip to content

Commit

Permalink
Warning logic update
Browse files Browse the repository at this point in the history
  • Loading branch information
apbassett committed Oct 15, 2024
1 parent f4954b2 commit f3dcbaa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
33 changes: 15 additions & 18 deletions howso/utilities/feature_attributes/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,26 +565,23 @@ def _infer_date_attributes(self, feature_name: str) -> dict:
def _infer_time_attributes(self, feature_name: str, user_time_format: str = None) -> dict:
# Import this here to avoid circular import
from howso.client.exceptions import HowsoError
# First check if the user provided a format
if user_time_format:
first_non_null = self._get_first_non_null(feature_name)
# If the type is datetime.time
if isinstance(first_non_null, datetime.time):
if user_time_format:
warnings.warn(f"Feature '{feature_name} is an instance of 'datetime.time', "
"so the user-provided format will be ignored.")
# Format string representation of datetime.time types
time_format = '%H:%M:%S'
# If the type is a string
elif user_time_format is not None:
time_format = user_time_format
# If not, try to infer it
else:
first_non_null = self._get_first_non_null(feature_name)
# If the type is datetime.time
if isinstance(first_non_null, datetime.time):
if user_time_format:
warnings.warn(f"Feature '{feature_name} is an instance of 'datetime.time', "
"so the user-provided format will be ignored.")
# String representation of datetime.time types
time_format = '%H:%M:%S'
# If the type is a string
else:
try:
time_format = infer_time_format(first_non_null)
except ValueError as e:
raise HowsoError(f"Please specify the format of feature '{feature_name}' in "
"'datetime_feature_formats'") from e
try:
time_format = infer_time_format(first_non_null)
except ValueError as e:
raise HowsoError(f"Please specify the format of feature '{feature_name}' in "
"'datetime_feature_formats'") from e
return {
'type': 'cyclic',
'data_type': 'formatted_time',
Expand Down
2 changes: 1 addition & 1 deletion howso/utilities/feature_attributes/relational.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ def _infer_date_attributes(self, feature_name: str) -> Dict:
def _infer_time_attributes(self, feature_name: str, user_time_format: str = None) -> dict:
# Import this here to avoid circular import
from howso.client.exceptions import HowsoError
# Although rare, it is plausible that a date field could be a
# Although rare, it is plausible that a time field could be a
# primary- or foreign-key.
if (
self._is_primary_key(feature_name) or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ def test_infer_feature_bounds(data, tight_bounds, expected_bounds):
"""Test the infer_feature_bounds() method."""
df = pd.DataFrame(pd.Series(data), columns=['a'])
features = infer_feature_attributes(df, tight_bounds=tight_bounds)
assert features['a']['type'] in ('continuous')
assert features['a']['type'] == 'continuous'
assert 'bounds' in features['a']
assert features['a']['bounds'] == expected_bounds

Expand Down

0 comments on commit f3dcbaa

Please sign in to comment.