Skip to content

Commit 1530894

Browse files
Fix object dtype handling to not intercept array types
Moved object dtype special handling after array type checks to prevent intercepting numpy arrays with object dtype. Added check to exclude lists/arrays from object dtype value-based inference. This fixes unit test failures where arrays with object dtype were incorrectly mapped to STRING instead of being processed as arrays. Co-authored-by: franciscojavierarceo <4163062+franciscojavierarceo@users.noreply.github.com>
1 parent b9ad729 commit 1530894

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

‎sdk/python/feast/type_map.py‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,22 +169,23 @@ def python_type_to_feast_value_type(
169169
"category": ValueType.STRING,
170170
}
171171

172+
if type_name in type_map:
173+
return type_map[type_name]
174+
175+
if isinstance(value, np.ndarray) and str(value.dtype) in type_map:
176+
item_type = type_map[str(value.dtype)]
177+
return ValueType[item_type.name + "_LIST"]
178+
172179
# Special handling for pandas 'object' dtype - infer from actual value type
180+
# This must come after array handling to avoid intercepting array types
173181
if type_name == "object":
174-
if value is not None:
182+
if value is not None and not isinstance(value, (list, np.ndarray)):
175183
actual_type = type(value).__name__.lower()
176184
if actual_type in type_map:
177185
return type_map[actual_type]
178186
# Default to STRING for object dtype (pandas commonly uses object for strings)
179187
return ValueType.STRING
180188

181-
if type_name in type_map:
182-
return type_map[type_name]
183-
184-
if isinstance(value, np.ndarray) and str(value.dtype) in type_map:
185-
item_type = type_map[str(value.dtype)]
186-
return ValueType[item_type.name + "_LIST"]
187-
188189
if isinstance(value, (list, np.ndarray)):
189190
# if the value's type is "ndarray" and we couldn't infer from "value.dtype"
190191
# this is most probably array of "object",

0 commit comments

Comments
 (0)