aws / aws/sagemaker-python-sdk

load_feature_definitions_from_dataframe() doesn't recognize pandas nullable dtypes (Float64, Int64)

Đã đóng
#5,675 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
2.3k
Fork
1.3k
Merge trung bình
1 ngày 22 giờ
Pull request đã merge (30 ngày)
35

Mô tả

**PySDK Version**
PySDK 3.6.0

**Describe the bug**
load_feature_definitions_from_dataframe() in sagemaker.mlops.feature_store only recognizes numpy dtypes (float64, int64, etc.) but not pandas nullable dtypes (Float64, Int64, string). When a DataFrame uses nullable dtypes (common after calling pd.DataFrame.convert_dtypes()), all numeric columns are incorrectly mapped to StringFeatureDefinition.

**To reproduce**
```
import pandas as pd
from sagemaker.mlops.feature_store import load_feature_definitions_from_dataframe

# Create a DataFrame with numpy dtypes (works correctly)
df_numpy = pd.DataFrame({
"id": [1, 2, 3],
"price": [1.1, 2.2, 3.3],
"name": ["a", "b", "c"],
})
print("numpy dtypes:", {c: str(df_numpy[c].dtype) for c in df_numpy.columns})
# {'id': 'int64', 'price': 'float64', 'name': 'object'}

defs = load_feature_definitions_from_dataframe(df_numpy)
for d in defs:
print(f" {d.feature_name}: {d.feature_type}")

# Now convert to pandas nullable dtypes (common pattern)
df_nullable = df_numpy.convert_dtypes()
print("\nnullable dtypes:", {c: str(df_nullable[c].dtype) for c in df_nullable.columns})
# {'id': 'Int64', 'price': 'Float64', 'name': 'string'}

defs = load_feature_definitions_from_dataframe(df_nullable)
for d in defs:
print(f" {d.feature_name}: {d.feature_type}")
```

Root cause

In sagemaker/mlops/feature_store/feature_utils.py, _INTEGER_TYPES and _FLOAT_TYPES only contain lowercase numpy dtype names:

_INTEGER_TYPES = {'int8', 'int16', 'int32', 'int64', 'int_', 'uint8', 'uint16', 'uint32', 'uint64'}
_FLOAT_TYPES = {'float16', 'float32', 'float64', 'float_'}

Pandas nullable dtypes are capitalized (Int64, Float64, etc.) and are not matched.

Suggested fix

Add nullable dtype names to the type sets:

_INTEGER_TYPES = {'int8', 'int16', 'int32', 'int64', 'int_',
'Int8', 'Int16', 'Int32', 'Int64',
'uint8', 'uint16', 'uint32', 'uint64',
'UInt8', 'UInt16', 'UInt32', 'UInt64'}
_FLOAT_TYPES = {'float16', 'float32', 'float64', 'float_',
'Float16', 'Float32', 'Float64'}

Or use case-insensitive comparison in _generate_feature_definition().

**Expected behavior**
Panda nullable types should get properly converted.

**System information**
A description of your system. Please provide:
- **SageMaker Python SDK version**: 3.6.0

I think this got fixed/addressed before.. but maybe that 2.x code didn't carray over to 3.x
https://github.com/aws/sagemaker-python-sdk/pull/3740/changes

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu trong sagemaker/mlops/feature_store/feature_utils.py, tập trung vào _generate_feature_definition() và các tập hợp _INTEGER_TYPES và _FLOAT_TYPES. Chạy bản tái hiện DataFrame được cung cấp và xác minh rằng các cột nullable kiểu Int64 và Float64 được ánh xạ tới các định nghĩa feature số thay vì StringFeatureDefinition, trong khi hành vi hiện có của numpy dtype vẫn không thay đổi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
pandas, python
Lĩnh vực
machine-learning
Loại issue
Lỗi
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.