forked from feast-dev/feast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.py
More file actions
60 lines (53 loc) · 1.92 KB
/
types.py
File metadata and controls
60 lines (53 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Copyright 2018 The Feast Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
from feast.sdk.resources.feature import ValueType
import numpy as np
# mapping of pandas dtypes to feast value type strings
DTYPE_TO_VALUE_TYPE_MAPPING = {
"float64": ValueType.DOUBLE,
"float32": ValueType.FLOAT,
"int64": ValueType.INT64,
"uint64": ValueType.INT64,
"int32": ValueType.INT32,
"uint32": ValueType.INT32,
"uint8": ValueType.INT32,
"int8": ValueType.INT32,
"bool": ValueType.BOOL,
"timedelta": ValueType.INT64,
"datetime64[ns]": ValueType.TIMESTAMP,
"datetime64[ns, tz]": ValueType.TIMESTAMP,
"category": ValueType.STRING,
"object": ValueType.STRING
}
# Mapping of feast value type to Pandas DataFrame dtypes
# Integer and floating values are all 64-bit for better integration
# with BigQuery data types
FEAST_VALUETYPE_TO_DTYPE = {
"bytesVal": np.byte,
"stringVal": np.object,
"int32Val": "Int32", # Use pandas nullable int type
"int64Val": "Int64", # Use pandas nullable int type
"doubleVal": np.float64,
"floatVal": np.float64,
"boolVal": np.bool,
"timestampVal": np.datetime64,
}
def dtype_to_value_type(dtype):
"""Returns the equivalent feast valueType for the given dtype
Args:
dtype (pandas.dtype): pandas dtype
Returns:
feast.types.ValueType2.ValueType: equivalent feast valuetype
"""
return DTYPE_TO_VALUE_TYPE_MAPPING[dtype.__str__()]