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

Update type conversion from pandas to timestamp to support various the timestamp types #1603

Merged
merged 4 commits into from
Jun 2, 2021
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
4 changes: 1 addition & 3 deletions sdk/python/feast/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,7 @@ def __init__(
self._file_options = FileOptions(file_format=file_format, file_url=file_url)

super().__init__(
event_timestamp_column
or self._infer_event_timestamp_column(r"timestamp\[\w\w\]"),
event_timestamp_column or self._infer_event_timestamp_column(r"^timestamp"),
created_timestamp_column,
field_mapping,
date_partition_column,
Expand Down Expand Up @@ -744,7 +743,6 @@ def get_table_column_names_and_types(self) -> Iterable[Tuple[str, str]]:
from google.cloud import bigquery

client = bigquery.Client()
bq_columns_query = ""
name_type_pairs = []
if self.table_ref is not None:
project_id, dataset_id, table_id = self.table_ref.split(".")
Expand Down
13 changes: 9 additions & 4 deletions sdk/python/feast/type_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import re
from datetime import datetime, timezone
from typing import Any, Dict, List, Union

Expand Down Expand Up @@ -438,8 +439,14 @@ def pa_to_value_type(pa_type: object):


def pa_to_feast_value_type(value: Union[pa.lib.ChunkedArray, str]) -> ValueType:
value_type = (
value.type.__str__() if isinstance(value, pa.lib.ChunkedArray) else value
Copy link
Member

Choose a reason for hiding this comment

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

Would you mind explaining this line?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is moved from line 459 - basically this converts the type of a pandas column into a string representation, if the stringified version has not already been passed in.

)

if re.match(r"^timestamp", value_type):
return ValueType.INT64

type_map = {
"timestamp[ms]": ValueType.INT64,
"int32": ValueType.INT32,
"int64": ValueType.INT64,
"double": ValueType.DOUBLE,
Expand All @@ -455,9 +462,7 @@ def pa_to_feast_value_type(value: Union[pa.lib.ChunkedArray, str]) -> ValueType:
"list<item: binary>": ValueType.BYTES_LIST,
"list<item: bool>": ValueType.BOOL_LIST,
}
return type_map[
value.type.__str__() if isinstance(value, pa.lib.ChunkedArray) else value
]
return type_map[value_type]


def pa_column_to_timestamp_proto_column(column: pa.lib.ChunkedArray) -> List[Timestamp]:
Expand Down