Skip to content

Commit

Permalink
Merge pull request #766 from uber/plo/feature_ohe
Browse files Browse the repository at this point in the history
Fix issue 764 to handle edge case in one hot encoding transformation
  • Loading branch information
paullo0106 committed Apr 25, 2024
2 parents 2903c3d + e782426 commit cc30c4a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion causalml/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,11 @@ def transform(self, X):
variables into dummy variables
"""

X_new = None
for i, col in enumerate(X.columns):
X_col = self._transform_col(X[col], i)
if X_col is not None:
if i == 0:
if X_new is None:
X_new = X_col
else:
X_new = sparse.hstack((X_new, X_col))
Expand All @@ -208,6 +209,9 @@ def transform(self, X):
"{} --> {} features".format(col, self.label_encoder.label_maxes[i])
)

assert (
X_new is not None
), "no column was transformed, please check your dataframe input"
return X_new

def fit_transform(self, X, y=None):
Expand Down

0 comments on commit cc30c4a

Please sign in to comment.