Skip to content

Commit ec11a7c

Browse files
authored
feat: Update the Pydantic from v1 to v2 (#3948)
1 parent 5c9f592 commit ec11a7c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+333
-253
lines changed

sdk/python/feast/importer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import importlib
2-
from typing import Optional
32

43
from feast.errors import (
54
FeastClassImportError,
@@ -8,7 +7,7 @@
87
)
98

109

11-
def import_class(module_name: str, class_name: str, class_type: Optional[str] = None):
10+
def import_class(module_name: str, class_name: str, class_type: str = ""):
1211
"""
1312
Dynamically loads and returns a class from a module.
1413

sdk/python/feast/infra/contrib/spark_kafka_processor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from types import MethodType
2-
from typing import List, Optional
2+
from typing import List, Optional, no_type_check
33

44
import pandas as pd
55
from pyspark.sql import DataFrame, SparkSession
@@ -76,6 +76,8 @@ def ingest_stream_feature_view(
7676
online_store_query = self._write_stream_data(transformed_df, to)
7777
return online_store_query
7878

79+
# In the line 64 of __init__(), the "data_source" is assigned a stream_source (and has to be KafkaSource as in line 40).
80+
@no_type_check
7981
def _ingest_stream_data(self) -> StreamTable:
8082
"""Only supports json and avro formats currently."""
8183
if self.format == "json":

sdk/python/feast/infra/contrib/stream_processor.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from abc import ABC
1+
from abc import ABC, abstractmethod
22
from types import MethodType
33
from typing import TYPE_CHECKING, Optional
44

@@ -50,19 +50,22 @@ def __init__(
5050
self.sfv = sfv
5151
self.data_source = data_source
5252

53+
@abstractmethod
5354
def ingest_stream_feature_view(self, to: PushMode = PushMode.ONLINE) -> None:
5455
"""
5556
Ingests data from the stream source attached to the stream feature view; transforms the data
5657
and then persists it to the online store and/or offline store, depending on the 'to' parameter.
5758
"""
5859
raise NotImplementedError
5960

61+
@abstractmethod
6062
def _ingest_stream_data(self) -> StreamTable:
6163
"""
6264
Ingests data into a StreamTable.
6365
"""
6466
raise NotImplementedError
6567

68+
@abstractmethod
6669
def _construct_transformation_plan(self, table: StreamTable) -> StreamTable:
6770
"""
6871
Applies transformations on top of StreamTable object. Since stream engines use lazy
@@ -71,6 +74,7 @@ def _construct_transformation_plan(self, table: StreamTable) -> StreamTable:
7174
"""
7275
raise NotImplementedError
7376

77+
@abstractmethod
7478
def _write_stream_data(self, table: StreamTable, to: PushMode) -> None:
7579
"""
7680
Launches a job to persist stream data to the online store and/or offline store, depending

sdk/python/feast/infra/feature_servers/aws_lambda/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from typing import Literal
2+
13
from pydantic import StrictBool, StrictStr
2-
from pydantic.typing import Literal
34

45
from feast.infra.feature_servers.base_config import BaseFeatureServerConfig
56

sdk/python/feast/infra/feature_servers/base_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ class BaseFeatureServerConfig(FeastConfigBaseModel):
3030
enabled: StrictBool = False
3131
"""Whether the feature server should be launched."""
3232

33-
feature_logging: Optional[FeatureLoggingConfig]
33+
feature_logging: Optional[FeatureLoggingConfig] = None
3434
""" Feature logging configuration """

sdk/python/feast/infra/feature_servers/gcp_cloudrun/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from typing import Literal
2+
13
from pydantic import StrictBool
2-
from pydantic.typing import Literal
34

45
from feast.infra.feature_servers.base_config import BaseFeatureServerConfig
56

sdk/python/feast/infra/feature_servers/local_process/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pydantic.typing import Literal
1+
from typing import Literal
22

33
from feast.infra.feature_servers.base_config import BaseFeatureServerConfig
44

sdk/python/feast/infra/materialization/snowflake_engine.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import click
88
import pandas as pd
99
from colorama import Fore, Style
10-
from pydantic import Field, StrictStr
10+
from pydantic import ConfigDict, Field, StrictStr
1111
from pytz import utc
1212
from tqdm import tqdm
1313

@@ -72,9 +72,7 @@ class SnowflakeMaterializationEngineConfig(FeastConfigBaseModel):
7272

7373
schema_: Optional[str] = Field("PUBLIC", alias="schema")
7474
""" Snowflake schema name """
75-
76-
class Config:
77-
allow_population_by_field_name = True
75+
model_config = ConfigDict(populate_by_name=True)
7876

7977

8078
@dataclass

sdk/python/feast/infra/offline_stores/bigquery.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
Dict,
1111
Iterator,
1212
List,
13+
Literal,
1314
Optional,
1415
Tuple,
1516
Union,
@@ -19,8 +20,7 @@
1920
import pandas as pd
2021
import pyarrow
2122
import pyarrow.parquet
22-
from pydantic import ConstrainedStr, StrictStr, validator
23-
from pydantic.typing import Literal
23+
from pydantic import StrictStr, field_validator
2424
from tenacity import Retrying, retry_if_exception_type, stop_after_delay, wait_fixed
2525

2626
from feast import flags_helper
@@ -72,13 +72,6 @@ def get_http_client_info():
7272
return http_client_info.ClientInfo(user_agent=get_user_agent())
7373

7474

75-
class BigQueryTableCreateDisposition(ConstrainedStr):
76-
"""Custom constraint for table_create_disposition. To understand more, see:
77-
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.create_disposition"""
78-
79-
values = {"CREATE_NEVER", "CREATE_IF_NEEDED"}
80-
81-
8275
class BigQueryOfflineStoreConfig(FeastConfigBaseModel):
8376
"""Offline store config for GCP BigQuery"""
8477

@@ -102,10 +95,15 @@ class BigQueryOfflineStoreConfig(FeastConfigBaseModel):
10295
gcs_staging_location: Optional[str] = None
10396
""" (optional) GCS location used for offloading BigQuery results as parquet files."""
10497

105-
table_create_disposition: Optional[BigQueryTableCreateDisposition] = None
106-
""" (optional) Specifies whether the job is allowed to create new tables. The default value is CREATE_IF_NEEDED."""
98+
table_create_disposition: Literal[
99+
"CREATE_NEVER", "CREATE_IF_NEEDED"
100+
] = "CREATE_IF_NEEDED"
101+
""" (optional) Specifies whether the job is allowed to create new tables. The default value is CREATE_IF_NEEDED.
102+
Custom constraint for table_create_disposition. To understand more, see:
103+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.create_disposition
104+
"""
107105

108-
@validator("billing_project_id")
106+
@field_validator("billing_project_id")
109107
def project_id_exists(cls, v, values, **kwargs):
110108
if v and not values["project_id"]:
111109
raise ValueError(

sdk/python/feast/infra/offline_stores/contrib/athena_offline_store/athena.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
Dict,
99
Iterator,
1010
List,
11+
Literal,
1112
Optional,
1213
Tuple,
1314
Union,
@@ -18,7 +19,6 @@
1819
import pyarrow
1920
import pyarrow as pa
2021
from pydantic import StrictStr
21-
from pydantic.typing import Literal
2222
from pytz import utc
2323

2424
from feast import OnDemandFeatureView

0 commit comments

Comments
 (0)