Skip to content

Commit

Permalink
Update type conversion from pandas to timestamp to support various th…
Browse files Browse the repository at this point in the history
…e timestamp types (#1603)

* Fix precommit to run black on commit

Signed-off-by: Achal Shah <[email protected]>

* Update type conversion from pandas to timestamp to support various the specifications

Signed-off-by: Achal Shah <[email protected]>

* Undo precommit changs

Signed-off-by: Achal Shah <[email protected]>

* make format

Signed-off-by: Achal Shah <[email protected]>
  • Loading branch information
achals authored Jun 2, 2021
1 parent a2581c5 commit f29cb8c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
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
)

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

0 comments on commit f29cb8c

Please sign in to comment.