Skip to content

Commit 7939ea9

Browse files
authored
Merge pull request #40 from jGaboardi/02_ruffen_lint
Lint with `ruff`
2 parents 7cffe56 + b8ce111 commit 7939ea9

File tree

8 files changed

+49
-36
lines changed

8 files changed

+49
-36
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![Continuous Integration](https://github.com/pysal/spglm/actions/workflows/testing.yml/badge.svg)](https://github.com/pysal/spglm/actions/workflows/testing.yml)
55
[![Documentation Status](https://readthedocs.org/projects/spglm/badge/?version=latest)](https://spglm.readthedocs.io/en/latest/?badge=latest)
66
[![PyPI version](https://badge.fury.io/py/spglm.svg)](https://badge.fury.io/py/spglm)
7+
[![codecov](https://codecov.io/gh/pysal/spglm/branch/main/graph/badge.svg)](https://codecov.io/gh/pysal/spglm)
78

89

910
This module is an adaptation of a portion of [GLM functionality from the

spglm/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__version__ = "1.0.8"
22

3-
from . import glm
4-
from . import family
5-
from . import utils
6-
from . import iwls
3+
from . import glm # noqa F401
4+
from . import family # noqa F401
5+
from . import utils # noqa F401
6+
from . import iwls # noqa F401

spglm/base.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,10 @@ def cov_params(
306306
"l1",
307307
"l1_cvxopt_cp",
308308
]:
309-
dot_fun = nan_dot
309+
######################################################################
310+
# TODO - remove GH#38
311+
dot_fun = nan_dot # noqa F821 - `nan_dot` not defined - should remove
312+
######################################################################
310313
else:
311314
dot_fun = np.dot
312315

@@ -397,9 +400,9 @@ def conf_int(self, alpha=0.05, cols=None, method="default"):
397400
>>> model = GLM(y, X)
398401
>>> results = model.fit()
399402
>>> results.conf_int()
400-
array([[ 20.57281401, 72.28355135],
401-
[ -0.42138121, 1.67934915],
402-
[ -0.84292086, -0.12685622]])
403+
array([[20.57281401, 72.28355135],
404+
[-0.42138121, 1.67934915],
405+
[-0.84292086, -0.12685622]])
403406
404407
Notes
405408
-----

spglm/family.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ def __init__(self, link=L.logit): # , n=1.):
797797
self.link = link()
798798

799799
def starting_mu(self, y):
800-
"""
800+
r"""
801801
The starting values for the IRLS algorithm for the Binomial family.
802802
A good choice for the binomial family is :math:`\mu_0 = (Y_i + 0.5)/2`
803803
"""
@@ -980,7 +980,7 @@ def resid_anscombe(self, endog, mu):
980980
Journal of the Royal Statistical Society B. 30, 248-75.
981981
982982
"""
983-
cox_snell = lambda x: (
983+
cox_snell = lambda x: ( # noqa E731 - skip "don't use lambda"
984984
special.betainc(2 / 3.0, 2 / 3.0, x) * special.beta(2 / 3.0, 2 / 3.0)
985985
)
986986
return np.sqrt(self.n) * (

spglm/glm.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -234,26 +234,26 @@ class GLMResults(LikelihoodModelResults):
234234
tr_S : trace of the hat matrix S
235235
resid_response : array
236236
response residuals; defined as y-mu
237-
resid_pearson : array
238-
Pearson residuals; defined as (y-mu)/sqrt(VAR(mu))
239-
where VAR is the distribution specific variance
240-
function; see family.py and varfuncs.py for more information.
241-
resid_working : array
242-
Working residuals; the working residuals are defined as
243-
resid_response/link'(mu); see links.py for the
244-
derivatives of the link functions.
245-
246-
resid_anscombe : array
247-
Anscombe residuals; see family.py for
248-
distribution-specific Anscombe residuals.
249-
250-
resid_deviance : array
251-
deviance residuals; see family.py for
252-
distribution-specific deviance residuals.
253-
254-
pearson_chi2 : float
255-
chi-Squared statistic is defined as the sum
256-
of the squares of the Pearson residuals
237+
resid_pearson : array
238+
Pearson residuals; defined as (y-mu)/sqrt(VAR(mu))
239+
where VAR is the distribution specific variance
240+
function; see family.py and varfuncs.py for more information.
241+
resid_working : array
242+
Working residuals; the working residuals are defined as
243+
resid_response/link'(mu); see links.py for the
244+
derivatives of the link functions.
245+
246+
resid_anscombe : array
247+
Anscombe residuals; see family.py for
248+
distribution-specific Anscombe residuals.
249+
250+
resid_deviance : array
251+
deviance residuals; see family.py for
252+
distribution-specific deviance residuals.
253+
254+
pearson_chi2 : float
255+
chi-Squared statistic is defined as the sum
256+
of the squares of the Pearson residuals
257257
258258
normalized_cov_params : array
259259
k*k, approximates [X.T*X]-1
@@ -339,7 +339,7 @@ def pearson_chi2(self):
339339
@cache_readonly
340340
def null(self):
341341
y = np.reshape(self.y, (-1, 1))
342-
model = self.model
342+
model = self.model # noqa F841 - `model` never used
343343
X = np.ones((len(y), 1))
344344
null_mod = GLM(y, X, family=self.family, offset=self.offset, constant=False)
345345
return null_mod.fit().mu

spglm/iwls.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from scipy import linalg
33
import numpy.linalg as la
44
from scipy import sparse as sp
5-
from scipy.sparse import linalg as spla
65
from spreg.utils import spdot, spmultiply
76
from .family import Binomial, Poisson
87

spglm/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ def _bit_length_26(x):
1717
except ImportError:
1818
import re
1919

20-
string_types = basestring
20+
######################################################################
21+
# TODO - remove GH#39
22+
string_types = basestring # noqa F821 - `basestring` not defined - should remove
23+
######################################################################
2124

2225
class NumpyVersion:
2326
"""Parse and compare numpy version strings.
@@ -365,7 +368,7 @@ def __get__(self, obj, type=None):
365368
setattr(_cache, name, _cachedval)
366369
# Update the reset list if needed (and possible)
367370
resetlist = self.resetlist
368-
if resetlist is not ():
371+
if resetlist != ():
369372
try:
370373
_cache._resetdict[name] = self.resetlist
371374
except AttributeError:

spglm/varfuncs.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,16 @@ def deriv(self, mu):
114114
"""
115115
Derivative of the variance function v'(mu)
116116
"""
117-
from statsmodels.tools.numdiff import approx_fprime_cs, approx_fprime
117+
118+
########################################################################
119+
# `approx_fprime_cs` is imported by unused
120+
from statsmodels.tools.numdiff import approx_fprime_cs # noqa F401
118121

119122
# return approx_fprime_cs(mu, self) # TODO fix breaks in `fabs
123+
########################################################################
124+
125+
from statsmodels.tools.numdiff import approx_fprime
126+
120127
# TODO: diag is workaround problem with numdiff for 1d
121128
return np.diag(approx_fprime(mu, self))
122129

@@ -205,7 +212,7 @@ def deriv(self, mu):
205212
"""
206213
Derivative of the variance function v'(mu)
207214
"""
208-
from statsmodels.tools.numdiff import approx_fprime_cs, approx_fprime
215+
from statsmodels.tools.numdiff import approx_fprime_cs
209216

210217
# TODO: diag workaround proplem with numdiff for 1d
211218
return np.diag(approx_fprime_cs(mu, self))

0 commit comments

Comments
 (0)