Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions feathr_project/feathr/definition/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ def __init__(self,
registry_tags: Optional[Dict[str, str]] = None,
):
FeatureBase.validate_feature_name(name)

# Validate the feature type
if not isinstance(feature_type, FeatureType):
raise KeyError(f'Feature type must be a FeatureType class, like INT32, but got {feature_type}')

self.name = name
self.feature_type = feature_type
self.registry_tags=registry_tags
Expand Down
4 changes: 4 additions & 0 deletions feathr_project/feathr/definition/typed_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def __init__(self,
full_name: Optional[str] = None,
description: Optional[str] = None,
key_column_alias: Optional[str] = None) -> None:
# Validate the key_column type
if not isinstance(key_column_type, ValueType):
raise KeyError(f'key_column_type must be a ValueType, like Value.INT32, but got {key_column_type}')

self.key_column = key_column
self.key_column_type = key_column_type
self.full_name = full_name
Expand Down
24 changes: 24 additions & 0 deletions feathr_project/test/unit/test_dtype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pytest
from feathr import Feature, TypedKey, ValueType, INT32


def test_key_type():
key = TypedKey(key_column="key", key_column_type=ValueType.INT32)
assert key.key_column_type == ValueType.INT32

with pytest.raises(KeyError):
key = TypedKey(key_column="key", key_column_type=INT32)

def test_feature_type():
key = TypedKey(key_column="key", key_column_type=ValueType.INT32)

feature = Feature(name="name",
key=key,
feature_type=INT32)

assert feature.feature_type == INT32

with pytest.raises(KeyError):
feature = Feature(name="name",
key=key,
feature_type=ValueType.INT32)