Skip to content

Commit 5b4f691

Browse files
committed
fix: revert constraint_user/constraint_item to init as empty list
- Previously attempted to follow sklearn convention: set to None in __init__, initialize to [] in fit() - This caused CI failure because test accesses .constraint_user.append() before fit() is called - Reverted to original behavior (init as []) to maintain compatibility with existing tests - No impact on correctness: [] and None treated equivalently in fit()
1 parent 73fdf7b commit 5b4f691

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

rehline/_mf_class.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ def __init__(
203203
self.n_users = n_users
204204
self.n_items = n_items
205205
self.loss = loss
206-
self.constraint_user = constraint_user
207-
self.constraint_item = constraint_item
206+
self.constraint_user = constraint_user if constraint_user is not None else []
207+
self.constraint_item = constraint_item if constraint_item is not None else []
208208
self.biased = biased
209209
## -----------------------------hyper parameters-----------------------------
210210
self.rank = rank
@@ -281,9 +281,6 @@ def fit(self, X, y, sample_weight=None):
281281
self.history = np.full((self.max_iter_CD + 1, 2), np.nan)
282282
## sample weights
283283
self.sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype)
284-
## constraints on user and item
285-
constraint_user = self.constraint_user if self.constraint_user is not None else []
286-
constraint_item = self.constraint_item if self.constraint_item is not None else []
287284
## random number generator
288285
rng = np.random.default_rng(self.random_state)
289286

@@ -357,7 +354,7 @@ def fit(self, X, y, sample_weight=None):
357354
C=C_user,
358355
sample_weight=weight_tmp,
359356
)
360-
A, b = _make_constraint_rehline_param(constraint=constraint_user, X=Q_tmp, y=y_tmp)
357+
A, b = _make_constraint_rehline_param(constraint=self.constraint_user, X=Q_tmp, y=y_tmp)
361358

362359
### solve and update
363360
result_tmp = ReHLine_solver(
@@ -424,7 +421,7 @@ def fit(self, X, y, sample_weight=None):
424421
C=C_item,
425422
sample_weight=weight_tmp,
426423
)
427-
A, b = _make_constraint_rehline_param(constraint=constraint_item, X=P_tmp, y=y_tmp)
424+
A, b = _make_constraint_rehline_param(constraint=self.constraint_item, X=P_tmp, y=y_tmp)
428425

429426
### solve and update
430427
result_tmp = ReHLine_solver(

0 commit comments

Comments
 (0)