Skip to content

Commit

Permalink
Convert to pandas at the correct place
Browse files Browse the repository at this point in the history
  • Loading branch information
stanmart committed Aug 16, 2023
1 parent e691470 commit 6b17808
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions src/glum/_glm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,16 @@ def linear_predictor(
elif alpha is not None:
alpha_index = [self._find_alpha_index(a) for a in alpha] # type: ignore

if isinstance(X, pd.DataFrame):
if hasattr(self, "feature_dtypes_"):
X = _align_df_categories(X, self.feature_dtypes_)

X = tm.from_pandas(
X,
drop_first=self.drop_first,
categorical_format=self.categorical_format,
)

X = check_array_tabmat_compliant(
X,
accept_sparse=["csr", "csc", "coo"],
Expand Down Expand Up @@ -1307,25 +1317,6 @@ def predict(
array, shape (n_samples, n_alphas)
Predicted values times ``sample_weight``.
"""
if isinstance(X, pd.DataFrame):
if hasattr(self, "feature_dtypes_"):
X = _align_df_categories(X, self.feature_dtypes_)

X = tm.from_pandas(
X,
drop_first=self.drop_first,
categorical_format=self.categorical_format,
)

X = check_array_tabmat_compliant(
X,
accept_sparse=["csr", "csc", "coo"],
dtype="numeric",
copy=self._should_copy_X(),
ensure_2d=True,
allow_nd=False,
drop_first=self.drop_first,
)
eta = self.linear_predictor(
X, offset=offset, alpha_index=alpha_index, alpha=alpha
)
Expand Down

0 comments on commit 6b17808

Please sign in to comment.