Skip to content

Commit ed97d7a

Browse files
committed
eliminate some unnessary type conversions
1 parent a7e2d9e commit ed97d7a

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

python/interpret-core/interpret/utils/_clean_x.py

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,8 @@ def _process_pandas_column(X_col, is_predict, feature_type, min_unique_continuou
985985
feature_type,
986986
None,
987987
None,
988-
*_process_continuous(X_col.values, None),
988+
X_col.values.astype(np.float64, "C", copy=False),
989+
None,
989990
)
990991
if is_predict:
991992
# called under: predict. feature_type == "nominal" or feature_type == "ordinal"
@@ -1063,21 +1064,21 @@ def _process_pandas_column(X_col, is_predict, feature_type, min_unique_continuou
10631064
return _process_arrayish(X_col, None, feature_type, min_unique_continuous)
10641065
elif issubclass(tt, _intbool_types):
10651066
# this handles Int8Dtype to Int64Dtype, UInt8Dtype to UInt64Dtype, and BooleanDtype
1067+
1068+
if feature_type == "continuous":
1069+
# called under: fit or predict
1070+
return (
1071+
feature_type,
1072+
None,
1073+
None,
1074+
X_col.values.astype(np.float64),
1075+
None,
1076+
)
1077+
10661078
if X_col.hasnans:
10671079
# if hasnans is true then there is definetly a real missing value in there and not just a mask
10681080
# if X_col is a special type like UInt64Dtype convert it to numpy using astype
10691081

1070-
if feature_type == "continuous":
1071-
# called under: fit or predict
1072-
return (
1073-
feature_type,
1074-
None,
1075-
None,
1076-
*_process_continuous(
1077-
X_col.dropna().values.astype(tt, copy=False),
1078-
X_col.notna().values,
1079-
),
1080-
)
10811082
if is_predict:
10821083
# called under: predict. feature_type == "nominal" or feature_type == "ordinal"
10831084
return (
@@ -1096,14 +1097,6 @@ def _process_pandas_column(X_col, is_predict, feature_type, min_unique_continuou
10961097
)
10971098
# if X_col is a special type like UInt64Dtype convert it to numpy using astype
10981099

1099-
if feature_type == "continuous":
1100-
# called under: fit or predict
1101-
return (
1102-
feature_type,
1103-
None,
1104-
None,
1105-
*_process_continuous(X_col.values.astype(tt, copy=False), None),
1106-
)
11071100
if is_predict:
11081101
# called under: predict. feature_type == "nominal" or feature_type == "ordinal"
11091102
return (

0 commit comments

Comments
 (0)