Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint with ruff #40

Merged
merged 5 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![Continuous Integration](https://github.com/pysal/spglm/actions/workflows/testing.yml/badge.svg)](https://github.com/pysal/spglm/actions/workflows/testing.yml)
[![Documentation Status](https://readthedocs.org/projects/spglm/badge/?version=latest)](https://spglm.readthedocs.io/en/latest/?badge=latest)
[![PyPI version](https://badge.fury.io/py/spglm.svg)](https://badge.fury.io/py/spglm)
[![codecov](https://codecov.io/gh/pysal/spglm/branch/main/graph/badge.svg)](https://codecov.io/gh/pysal/spglm)


This module is an adaptation of a portion of [GLM functionality from the
Expand Down
8 changes: 4 additions & 4 deletions spglm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__version__ = "1.0.8"

from . import glm
from . import family
from . import utils
from . import iwls
from . import glm # noqa F401
from . import family # noqa F401
from . import utils # noqa F401
from . import iwls # noqa F401
11 changes: 7 additions & 4 deletions spglm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,10 @@
"l1",
"l1_cvxopt_cp",
]:
dot_fun = nan_dot
######################################################################
# TODO - remove GH#38
dot_fun = nan_dot # noqa F821 - `nan_dot` not defined - should remove

Check warning on line 311 in spglm/base.py

View check run for this annotation

Codecov / codecov/patch

spglm/base.py#L311

Added line #L311 was not covered by tests
######################################################################
else:
dot_fun = np.dot

Expand Down Expand Up @@ -397,9 +400,9 @@
>>> model = GLM(y, X)
>>> results = model.fit()
>>> results.conf_int()
array([[ 20.57281401, 72.28355135],
[ -0.42138121, 1.67934915],
[ -0.84292086, -0.12685622]])
array([[20.57281401, 72.28355135],
[-0.42138121, 1.67934915],
[-0.84292086, -0.12685622]])

Notes
-----
Expand Down
4 changes: 2 additions & 2 deletions spglm/family.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ def __init__(self, link=L.logit): # , n=1.):
self.link = link()

def starting_mu(self, y):
"""
r"""
The starting values for the IRLS algorithm for the Binomial family.
A good choice for the binomial family is :math:`\mu_0 = (Y_i + 0.5)/2`
"""
Expand Down Expand Up @@ -980,7 +980,7 @@ def resid_anscombe(self, endog, mu):
Journal of the Royal Statistical Society B. 30, 248-75.

"""
cox_snell = lambda x: (
cox_snell = lambda x: ( # noqa E731 - skip "don't use lambda"
special.betainc(2 / 3.0, 2 / 3.0, x) * special.beta(2 / 3.0, 2 / 3.0)
)
return np.sqrt(self.n) * (
Expand Down
42 changes: 21 additions & 21 deletions spglm/glm.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,26 +234,26 @@ class GLMResults(LikelihoodModelResults):
tr_S : trace of the hat matrix S
resid_response : array
response residuals; defined as y-mu
resid_pearson : array
Pearson residuals; defined as (y-mu)/sqrt(VAR(mu))
where VAR is the distribution specific variance
function; see family.py and varfuncs.py for more information.
resid_working : array
Working residuals; the working residuals are defined as
resid_response/link'(mu); see links.py for the
derivatives of the link functions.

resid_anscombe : array
Anscombe residuals; see family.py for
distribution-specific Anscombe residuals.

resid_deviance : array
deviance residuals; see family.py for
distribution-specific deviance residuals.

pearson_chi2 : float
chi-Squared statistic is defined as the sum
of the squares of the Pearson residuals
resid_pearson : array
Pearson residuals; defined as (y-mu)/sqrt(VAR(mu))
where VAR is the distribution specific variance
function; see family.py and varfuncs.py for more information.
resid_working : array
Working residuals; the working residuals are defined as
resid_response/link'(mu); see links.py for the
derivatives of the link functions.

resid_anscombe : array
Anscombe residuals; see family.py for
distribution-specific Anscombe residuals.

resid_deviance : array
deviance residuals; see family.py for
distribution-specific deviance residuals.

pearson_chi2 : float
chi-Squared statistic is defined as the sum
of the squares of the Pearson residuals

normalized_cov_params : array
k*k, approximates [X.T*X]-1
Expand Down Expand Up @@ -339,7 +339,7 @@ def pearson_chi2(self):
@cache_readonly
def null(self):
y = np.reshape(self.y, (-1, 1))
model = self.model
model = self.model # noqa F841 - `model` never used
X = np.ones((len(y), 1))
null_mod = GLM(y, X, family=self.family, offset=self.offset, constant=False)
return null_mod.fit().mu
Expand Down
1 change: 0 additions & 1 deletion spglm/iwls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from scipy import linalg
import numpy.linalg as la
from scipy import sparse as sp
from scipy.sparse import linalg as spla
from spreg.utils import spdot, spmultiply
from .family import Binomial, Poisson

Expand Down
7 changes: 5 additions & 2 deletions spglm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
except ImportError:
import re

string_types = basestring
######################################################################
# TODO - remove GH#39
string_types = basestring # noqa F821 - `basestring` not defined - should remove

Check warning on line 22 in spglm/utils.py

View check run for this annotation

Codecov / codecov/patch

spglm/utils.py#L22

Added line #L22 was not covered by tests
######################################################################

class NumpyVersion:
"""Parse and compare numpy version strings.
Expand Down Expand Up @@ -365,7 +368,7 @@
setattr(_cache, name, _cachedval)
# Update the reset list if needed (and possible)
resetlist = self.resetlist
if resetlist is not ():
if resetlist != ():
try:
_cache._resetdict[name] = self.resetlist
except AttributeError:
Expand Down
11 changes: 9 additions & 2 deletions spglm/varfuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,16 @@
"""
Derivative of the variance function v'(mu)
"""
from statsmodels.tools.numdiff import approx_fprime_cs, approx_fprime

########################################################################
# `approx_fprime_cs` is imported by unused
from statsmodels.tools.numdiff import approx_fprime_cs # noqa F401

Check warning on line 120 in spglm/varfuncs.py

View check run for this annotation

Codecov / codecov/patch

spglm/varfuncs.py#L120

Added line #L120 was not covered by tests
jGaboardi marked this conversation as resolved.
Show resolved Hide resolved

# return approx_fprime_cs(mu, self) # TODO fix breaks in `fabs
########################################################################

from statsmodels.tools.numdiff import approx_fprime

Check warning on line 125 in spglm/varfuncs.py

View check run for this annotation

Codecov / codecov/patch

spglm/varfuncs.py#L125

Added line #L125 was not covered by tests

# TODO: diag is workaround problem with numdiff for 1d
return np.diag(approx_fprime(mu, self))

Expand Down Expand Up @@ -205,7 +212,7 @@
"""
Derivative of the variance function v'(mu)
"""
from statsmodels.tools.numdiff import approx_fprime_cs, approx_fprime
from statsmodels.tools.numdiff import approx_fprime_cs

Check warning on line 215 in spglm/varfuncs.py

View check run for this annotation

Codecov / codecov/patch

spglm/varfuncs.py#L215

Added line #L215 was not covered by tests

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