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

fix: Make name a keyword arg for the Entity class #2467

Merged
merged 3 commits into from
Mar 30, 2022
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
2 changes: 1 addition & 1 deletion go/internal/feast/ondemandfeatureview.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

type OnDemandFeatureView struct {
base *BaseFeatureView
base *BaseFeatureView
sourceFeatureViewProjections map[string]*FeatureViewProjection
sourceRequestDataSources map[string]*core.DataSource_RequestDataOptions
}
Expand Down
25 changes: 22 additions & 3 deletions sdk/python/feast/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import warnings
from datetime import datetime
from typing import Dict, Optional

Expand Down Expand Up @@ -53,17 +54,35 @@ class Entity:
@log_exceptions
def __init__(
self,
name: str,
*args,
name: Optional[str] = None,
value_type: ValueType = ValueType.UNKNOWN,
description: str = "",
join_key: Optional[str] = None,
tags: Optional[Dict[str, str]] = None,
owner: str = "",
):
"""Creates an Entity object."""
self.name = name
if len(args) == 1:
warnings.warn(
(
"Entity name should be specified as a keyword argument instead of a positional arg."
"Feast 0.23+ will not support positional arguments to construct Entities"
),
DeprecationWarning,
)
if len(args) > 1:
raise ValueError(
"All arguments to construct an entity should be specified as keyword arguments only"
)

self.name = args[0] if len(args) > 0 else name

if not self.name:
raise ValueError("Name needs to be specified")

self.value_type = value_type
self.join_key = join_key if join_key else name
self.join_key = join_key if join_key else self.name
self.description = description
self.tags = tags if tags is not None else {}
self.owner = owner
Expand Down
41 changes: 32 additions & 9 deletions sdk/python/tests/unit/test_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,55 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import assertpy
import pytest

from feast.entity import Entity
from feast.value_type import ValueType


def test_join_key_default():
entity = Entity("my-entity", description="My entity", value_type=ValueType.STRING)
with pytest.deprecated_call():
entity = Entity(
"my-entity", description="My entity", value_type=ValueType.STRING
)
assert entity.join_key == "my-entity"


def test_entity_class_contains_tags():
entity = Entity(
"my-entity",
description="My entity",
value_type=ValueType.STRING,
tags={"key1": "val1", "key2": "val2"},
)
with pytest.deprecated_call():
entity = Entity(
"my-entity",
description="My entity",
value_type=ValueType.STRING,
tags={"key1": "val1", "key2": "val2"},
)
assert "key1" in entity.tags.keys() and entity.tags["key1"] == "val1"
assert "key2" in entity.tags.keys() and entity.tags["key2"] == "val2"


def test_entity_without_tags_empty_dict():
entity = Entity("my-entity", description="My entity", value_type=ValueType.STRING)
with pytest.deprecated_call():
entity = Entity(
"my-entity", description="My entity", value_type=ValueType.STRING
)
assert entity.tags == dict()
assert len(entity.tags) == 0


def test_entity_without_description():
Entity("my-entity", value_type=ValueType.STRING)
with pytest.deprecated_call():
Entity("my-entity", value_type=ValueType.STRING)


def test_name_not_specified():
assertpy.assert_that(lambda: Entity(value_type=ValueType.STRING)).raises(ValueError)


def test_multiple_args():
assertpy.assert_that(lambda: Entity("a", ValueType.STRING)).raises(ValueError)


def test_name_keyword(recwarn):
Entity(name="my-entity", value_type=ValueType.STRING)
assert len(recwarn) == 0