Skip to content
Prev Previous commit
Next Next commit
Fix newly detected linting errors
Signed-off-by: Judah Rand <17158624+judahrand@users.noreply.github.com>
  • Loading branch information
judahrand committed Jan 21, 2022
commit 82dc11ffc73346ee5e08f66cc2e9d768995ea3f4
4 changes: 3 additions & 1 deletion sdk/python/feast/feature_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -1458,7 +1458,9 @@ def _read_from_online_store(
@staticmethod
def _populate_response_from_feature_data(
feature_data: Iterable[
Tuple[Iterable[Timestamp], Iterable["FieldStatus.ValueType"], Iterable[Value]]
Tuple[
Iterable[Timestamp], Iterable["FieldStatus.ValueType"], Iterable[Value]
]
],
indexes: Iterable[Iterable[int]],
online_features_response: GetOnlineFeaturesResponse,
Expand Down
Empty file.
Empty file.
4 changes: 2 additions & 2 deletions sdk/python/feast/infra/online_stores/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,13 @@ def _get_features_for_entity(
res_ts = Timestamp()
ts_val = res_val.pop(f"_ts:{feature_view}")
if ts_val:
res_ts.ParseFromString(ts_val)
res_ts.ParseFromString(bytes(ts_val))

res = {}
for feature_name, val_bin in res_val.items():
val = ValueProto()
if val_bin:
val.ParseFromString(val_bin)
val.ParseFromString(bytes(val_bin))
res[feature_name] = val

if not res:
Expand Down
2 changes: 2 additions & 0 deletions sdk/python/feast/repo_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re
import sys
from importlib.abc import Loader
from importlib.machinery import ModuleSpec
from pathlib import Path
from typing import List, Set, Union, cast

Expand Down Expand Up @@ -375,6 +376,7 @@ def init_repo(repo_name: str, template: str):
import importlib.util

spec = importlib.util.spec_from_file_location("bootstrap", str(bootstrap_path))
assert isinstance(spec, ModuleSpec)
bootstrap = importlib.util.module_from_spec(spec)
assert isinstance(spec.loader, Loader)
spec.loader.exec_module(bootstrap)
Expand Down
Empty file.
Empty file.
Empty file.
7 changes: 3 additions & 4 deletions sdk/python/feast/type_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import numpy as np
import pandas as pd
import pyarrow
from google.protobuf.pyext.cpp_message import GeneratedProtocolMessageType
from google.protobuf.timestamp_pb2 import Timestamp

from feast.protos.feast.types.Value_pb2 import (
Expand All @@ -32,7 +31,7 @@
StringList,
)
from feast.protos.feast.types.Value_pb2 import Value as ProtoValue
from feast.value_type import ValueType
from feast.value_type import ListType, ValueType


def feast_value_type_to_python_type(field_value_proto: ProtoValue) -> Any:
Expand Down Expand Up @@ -195,7 +194,7 @@ def _type_err(item, dtype):


PYTHON_LIST_VALUE_TYPE_TO_PROTO_VALUE: Dict[
ValueType, Tuple[GeneratedProtocolMessageType, str, List[Type]]
ValueType, Tuple[ListType, str, List[Type]]
] = {
ValueType.FLOAT_LIST: (
FloatList,
Expand Down Expand Up @@ -273,7 +272,7 @@ def _python_value_to_proto_value(
raise _type_err(first_invalid, valid_types[0])

return [
ProtoValue(**{field_name: proto_type(val=value)})
ProtoValue(**{field_name: proto_type(val=value)}) # type: ignore
if value is not None
else ProtoValue()
for value in values
Expand Down
22 changes: 22 additions & 0 deletions sdk/python/feast/value_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import enum
from typing import Type, Union

from feast.protos.feast.types.Value_pb2 import (
BoolList,
BytesList,
DoubleList,
FloatList,
Int32List,
Int64List,
StringList,
)


class ValueType(enum.Enum):
Expand All @@ -37,3 +48,14 @@ class ValueType(enum.Enum):
BOOL_LIST = 17
UNIX_TIMESTAMP_LIST = 18
NULL = 19


ListType = Union[
Type[BoolList],
Type[BytesList],
Type[DoubleList],
Type[FloatList],
Type[Int32List],
Type[Int64List],
Type[StringList],
]
20 changes: 19 additions & 1 deletion sdk/python/requirements/py3.7-ci-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,25 @@ typed-ast==1.5.1
types-futures==3.3.7
# via types-protobuf
types-protobuf==3.19.5
# via mypy-protobuf
# via
# feast (setup.py)
# mypy-protobuf
types-python-dateutil==2.8.8
# via feast (setup.py)
types-pytz==2021.3.4
# via feast (setup.py)
types-pyyaml==6.0.3
# via feast (setup.py)
types-redis==4.1.10
# via feast (setup.py)
types-requests==2.27.7
# via feast (setup.py)
types-setuptools==57.4.7
# via feast (setup.py)
types-tabulate==0.8.5
# via feast (setup.py)
types-urllib3==1.26.7
# via types-requests
typing-extensions==4.0.1
# via
# aiohttp
Expand Down
20 changes: 19 additions & 1 deletion sdk/python/requirements/py3.8-ci-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,25 @@ typed-ast==1.5.1
types-futures==3.3.7
# via types-protobuf
types-protobuf==3.19.5
# via mypy-protobuf
# via
# feast (setup.py)
# mypy-protobuf
types-python-dateutil==2.8.8
# via feast (setup.py)
types-pytz==2021.3.4
# via feast (setup.py)
types-pyyaml==6.0.3
# via feast (setup.py)
types-redis==4.1.10
# via feast (setup.py)
types-requests==2.27.7
# via feast (setup.py)
types-setuptools==57.4.7
# via feast (setup.py)
types-tabulate==0.8.5
# via feast (setup.py)
types-urllib3==1.26.7
# via types-requests
typing-extensions==4.0.1
# via
# libcst
Expand Down
20 changes: 19 additions & 1 deletion sdk/python/requirements/py3.9-ci-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,25 @@ typed-ast==1.5.1
types-futures==3.3.7
# via types-protobuf
types-protobuf==3.19.5
# via mypy-protobuf
# via
# feast (setup.py)
# mypy-protobuf
types-python-dateutil==2.8.8
# via feast (setup.py)
types-pytz==2021.3.4
# via feast (setup.py)
types-pyyaml==6.0.3
# via feast (setup.py)
types-redis==4.1.10
# via feast (setup.py)
types-requests==2.27.7
# via feast (setup.py)
types-setuptools==57.4.7
# via feast (setup.py)
types-tabulate==0.8.5
# via feast (setup.py)
types-urllib3==1.26.7
# via types-requests
typing-extensions==4.0.1
# via
# libcst
Expand Down
77 changes: 45 additions & 32 deletions sdk/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,38 +86,51 @@
"docker>=5.0.2",
]

CI_REQUIRED = [
"cryptography==3.3.2",
"flake8",
"black==19.10b0",
"isort>=5",
"grpcio-tools==1.34.0",
"grpcio-testing==1.34.0",
"minio==7.1.0",
"mock==2.0.0",
"moto",
"mypy==0.931",
"mypy-protobuf==3.1.0",
"avro==1.10.0",
"gcsfs",
"urllib3>=1.25.4",
"pytest>=6.0.0",
"pytest-cov",
"pytest-xdist",
"pytest-benchmark>=3.4.1",
"pytest-lazy-fixture==0.6.3",
"pytest-timeout==1.4.2",
"pytest-ordering==0.6.*",
"pytest-mock==1.10.4",
"Sphinx!=4.0.0,<4.4.0",
"sphinx-rtd-theme",
"testcontainers==3.4.2",
"adlfs==0.5.9",
"firebase-admin==4.5.2",
"pre-commit",
"assertpy==1.1",
"pip-tools",
] + GCP_REQUIRED + REDIS_REQUIRED + AWS_REQUIRED
CI_REQUIRED = (
[
"cryptography==3.3.2",
"flake8",
"black==19.10b0",
"isort>=5",
"grpcio-tools==1.34.0",
"grpcio-testing==1.34.0",
"minio==7.1.0",
"mock==2.0.0",
"moto",
"mypy==0.931",
"mypy-protobuf==3.1.0",
"avro==1.10.0",
"gcsfs",
"urllib3>=1.25.4",
"pytest>=6.0.0",
"pytest-cov",
"pytest-xdist",
"pytest-benchmark>=3.4.1",
"pytest-lazy-fixture==0.6.3",
"pytest-timeout==1.4.2",
"pytest-ordering==0.6.*",
"pytest-mock==1.10.4",
"Sphinx!=4.0.0,<4.4.0",
"sphinx-rtd-theme",
"testcontainers==3.4.2",
"adlfs==0.5.9",
"firebase-admin==4.5.2",
"pre-commit",
"assertpy==1.1",
"pip-tools",
"types-protobuf",
"types-python-dateutil",
"types-pytz",
"types-PyYAML",
"types-redis",
"types-requests",
"types-setuptools",
"types-tabulate",
]
+ GCP_REQUIRED
+ REDIS_REQUIRED
+ AWS_REQUIRED
)

DEV_REQUIRED = ["mypy-protobuf==1.*", "grpcio-testing==1.*"] + CI_REQUIRED

Expand Down
8 changes: 4 additions & 4 deletions sdk/python/tests/data/data_creator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime, timedelta
from typing import List
from typing import Dict, List, Optional

import pandas as pd
from pytz import timezone, utc
Expand Down Expand Up @@ -38,7 +38,7 @@ def create_dataset(


def get_entities_for_value_type(value_type: ValueType) -> List:
value_type_map = {
value_type_map: Dict[ValueType, List] = {
ValueType.INT32: [1, 2, 1, 3, 3],
ValueType.INT64: [1, 2, 1, 3, 3],
ValueType.FLOAT: [1.0, 2.0, 1.0, 3.0, 3.0],
Expand All @@ -48,13 +48,13 @@ def get_entities_for_value_type(value_type: ValueType) -> List:


def get_feature_values_for_dtype(
dtype: str, is_list: bool, has_empty_list: bool
dtype: Optional[str], is_list: bool, has_empty_list: bool
) -> List:
if dtype is None:
return [0.1, None, 0.3, 4, 5]
# TODO(adchia): for int columns, consider having a better error when dealing with None values (pandas int dfs can't
# have na)
dtype_map = {
dtype_map: Dict[str, List] = {
"int32": [1, 2, 3, 4, 5],
"int64": [1, 2, 3, 4, 5],
"float": [1.0, None, 3.0, 4.0, 5.0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ def get_local_server_port(self) -> int:

def table_name_from_data_source(ds: DataSource) -> Optional[str]:
if hasattr(ds, "table_ref"):
return ds.table_ref
return ds.table_ref # type: ignore
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, but why are we adding an ignore statement here? Was this an omission? We've not had to use ignores elsewhere in the code base, so this stood out.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was because I believe neither table not table_ref are actually attributes of DataSource - only its subclasses. The other option would have been a complex cast, I believe. This might be preferable but especially as it was in a test util I decided not to do that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There area handful of other # type: ignore comments around the codebase and I've also discovered that the typing around Protobufs is tricky and often seemingly wrong or unhelpful.

elif hasattr(ds, "table"):
return ds.table
return ds.table # type: ignore
return None


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, Optional
from typing import Dict, List, Optional

import pandas as pd
from google.cloud import bigquery
Expand All @@ -21,7 +21,7 @@ def __init__(self, project_name: str):
self.gcp_project = self.client.project
self.dataset_id = f"{self.gcp_project}.{project_name}"

self.tables = []
self.tables: List[str] = []

def create_dataset(self):
if not self.dataset:
Expand Down Expand Up @@ -50,7 +50,7 @@ def create_offline_store_config(self):
def create_data_source(
self,
df: pd.DataFrame,
destination_name: Optional[str] = None,
destination_name: str,
event_timestamp_column="ts",
created_timestamp_column="created_ts",
field_mapping: Dict[str, str] = None,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, Optional
from typing import Dict, List, Optional

import pandas as pd

Expand All @@ -14,7 +14,7 @@

class RedshiftDataSourceCreator(DataSourceCreator):

tables = []
tables: List[str] = []

def __init__(self, project_name: str):
super().__init__()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def find_asof_record(
filter_keys = filter_keys or []
filter_values = filter_values or []
assert len(filter_keys) == len(filter_values)
found_record = {}
found_record: Dict[str, Any] = {}
for record in records:
if (
all(
Expand Down
8 changes: 4 additions & 4 deletions sdk/python/tests/integration/registration/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import tempfile
import uuid
from contextlib import contextmanager
from pathlib import Path, PosixPath
from pathlib import Path
from textwrap import dedent

import pytest
Expand All @@ -26,10 +26,10 @@ def test_universal_cli(test_repo_config) -> None:

with tempfile.TemporaryDirectory() as repo_dir_name:
try:
repo_path = Path(repo_dir_name)
feature_store_yaml = make_feature_store_yaml(
project, test_repo_config, repo_dir_name
project, test_repo_config, repo_path
)
repo_path = Path(repo_dir_name)

repo_config = repo_path / "feature_store.yaml"

Expand Down Expand Up @@ -103,7 +103,7 @@ def test_universal_cli(test_repo_config) -> None:
runner.run(["teardown"], cwd=repo_path)


def make_feature_store_yaml(project, test_repo_config, repo_dir_name: PosixPath):
def make_feature_store_yaml(project, test_repo_config, repo_dir_name: Path):
offline_creator: DataSourceCreator = test_repo_config.offline_store_creator(project)

offline_store_config = offline_creator.create_offline_store_config()
Expand Down
Loading