Skip to content

Commit e5b26e1

Browse files
authored
Update change log for release (#880)
1 parent fb863f4 commit e5b26e1

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Changelog
88
=========
99

10-
3.1.0 - unreleased
10+
3.1.0 - 2024-11-11
1111
------------------
1212

1313
**New features:**

src/glum/_distribution.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,9 @@ def guess_intercept(
15101510
If the distribution and corresponding link are something else, we use the
15111511
Tweedie or normal solution, depending on the link function.
15121512
"""
1513+
if (not isinstance(link, IdentityLink)) and (len(np.unique(y)) == 1):
1514+
raise ValueError("No variation in `y`. Coefficients can't be estimated.")
1515+
15131516
avg_y = np.average(y, weights=sample_weight)
15141517

15151518
if isinstance(link, IdentityLink):

src/glum/_glm.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ def _one_over_var_inf_to_val(arr: np.ndarray, val: float) -> np.ndarray:
452452
453453
If values are zeros, return val.
454454
"""
455-
zeros = np.where(np.abs(arr) < np.sqrt(np.finfo(arr.dtype).eps))
455+
zeros = np.where(np.abs(arr) < 10 * np.sqrt(np.finfo(arr.dtype).eps))
456456
with np.errstate(divide="ignore"):
457457
one_over = 1 / arr
458458
one_over[zeros] = val
@@ -1104,7 +1104,7 @@ def _solve(
11041104
family=self._family_instance,
11051105
link=self._link_instance,
11061106
max_iter=max_iter,
1107-
max_inner_iter=self.max_inner_iter,
1107+
max_inner_iter=getattr(self, "max_inner_iter", 100_000),
11081108
gradient_tol=self._gradient_tol,
11091109
step_size_tol=self.step_size_tol,
11101110
fixed_inner_tol=fixed_inner_tol,
@@ -2544,12 +2544,14 @@ def _set_up_and_check_fit_args(
25442544
# This will prevent accidental upcasting later and slow operations on
25452545
# mixed-precision numbers
25462546
y = np.asarray(y, dtype=X.dtype)
2547+
25472548
sample_weight = _check_weights(
25482549
sample_weight,
25492550
y.shape[0], # type: ignore
25502551
X.dtype,
25512552
force_all_finite=force_all_finite,
25522553
)
2554+
25532555
offset = _check_offset(offset, y.shape[0], X.dtype) # type: ignore
25542556

25552557
# IMPORTANT NOTE: Since we want to minimize
@@ -2559,9 +2561,8 @@ def _set_up_and_check_fit_args(
25592561
# 1/2*deviance + L1 + L2 with deviance=sum(weights * unit_deviance)
25602562
weights_sum: float = np.sum(sample_weight) # type: ignore
25612563
sample_weight = sample_weight / weights_sum
2562-
#######################################################################
2563-
# 2b. convert to wrapper matrix types
2564-
#######################################################################
2564+
2565+
# Convert to wrapper matrix types
25652566
X = tm.as_tabmat(X)
25662567

25672568
self.feature_names_ = X.get_names(type="column", missing_prefix="_col_") # type: ignore

tests/glm/test_glm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ def get_small_x_y(
5656
estimator: Union[GeneralizedLinearRegressor, GeneralizedLinearRegressorCV],
5757
) -> tuple[np.ndarray, np.ndarray]:
5858
if isinstance(estimator, GeneralizedLinearRegressor):
59-
n_rows = 1
59+
n_rows = 2
6060
else:
6161
n_rows = 10
6262
x = np.ones((n_rows, 1), dtype=int)
63-
y = np.ones(n_rows) * 0.5
63+
y = np.array([0, 1] * (n_rows // 2)) * 0.5
6464
return x, y
6565

6666

@@ -222,7 +222,7 @@ def test_glm_family_argument_invalid_input(estimator):
222222
def test_glm_family_argument_as_exponential_dispersion_model(estimator, kwargs, family):
223223
X, y = get_small_x_y(estimator)
224224
glm = estimator(family=family(), **kwargs)
225-
glm.fit(X, y)
225+
glm.fit(X, np.where(y > family().lower_bound, y, y.max() / 2))
226226

227227

228228
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)