-
Notifications
You must be signed in to change notification settings - Fork 25
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 repo with ruff
#202
Lint repo with ruff
#202
Changes from 11 commits
03b21d0
fe4db56
a4b3f4e
891b425
5a00d05
9007cd4
147140f
f689cea
9972017
492c5db
0ca8a53
8a7e6f9
fc9993f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
files: "giddy\/" | ||
repos: | ||
- repo: https://github.com/psf/black | ||
rev: "23.9.1" | ||
hooks: | ||
- id: black | ||
language_version: python3 | ||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
rev: "v0.0.292" | ||
hooks: | ||
- id: ruff | ||
|
||
ci: | ||
autofix_prs: false | ||
autoupdate_schedule: quarterly |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
__all__ = ["Rose"] | ||
|
||
import warnings | ||
|
||
import numpy as np | ||
from libpysal import weights | ||
from libpysal.common import requires as _requires | ||
|
@@ -27,7 +27,8 @@ class Rose(object): | |
Parameters | ||
---------- | ||
Y : array (n,2) | ||
Columns correspond to end-point time periods to calculate LISA vectors for n object. | ||
Columns correspond to end-point time periods to | ||
calculate LISA vectors for n object. | ||
w : PySAL W | ||
Spatial weights object. | ||
k : int | ||
|
@@ -349,10 +350,10 @@ def plot_origin(self): # TODO add attribute option to color vectors | |
Plot vectors of positional transition of LISA values starting | ||
from the same origin. | ||
""" | ||
import matplotlib.cm as cm | ||
# import matplotlib.cm as cm | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For all commented out lines that I added, they were raising linting errors in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They can actually be entirely removed, but I decided to simply comment out for now so we can discuss. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. I think these lines are redundant and we should simply remove them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So these lines aren't actually redundant, it's just that |
||
import matplotlib.pyplot as plt | ||
|
||
ax = plt.subplot(111) | ||
# ax = plt.subplot(111) | ||
xlim = [self._dx.min(), self._dx.max()] | ||
ylim = [self._dy.min(), self._dy.max()] | ||
for x, y in zip(self._dx, self._dy): | ||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -124,7 +124,7 @@ def steady_state(P, fill_empty_classes=False): | |||||||
... | ||||||||
ValueError: Input transition probability matrix has 1 rows full of 0s. Please set fill_empty_classes=True to set diagonal elements for these rows to be 1 to make sure the matrix is stochastic. | ||||||||
|
||||||||
""" | ||||||||
""" # noqa E501 | ||||||||
|
||||||||
P = np.asarray(P) | ||||||||
rows0 = (P.sum(axis=1) == 0).sum() | ||||||||
|
@@ -204,7 +204,7 @@ def _mfpt_ergodic(P): | |||||||
for i in range(k): | ||||||||
A[:, i] = ss | ||||||||
A = A.transpose() | ||||||||
I = np.identity(k) | ||||||||
I = np.identity(k) # noqa E741 | ||||||||
Z = la.inv(I - P + A) | ||||||||
E = np.ones_like(Z) | ||||||||
A_diag = np.diag(A) | ||||||||
|
@@ -293,7 +293,7 @@ def mfpt(P, fill_empty_classes=False): | |||||||
Traceback (most recent call last): | ||||||||
... | ||||||||
ValueError: Input transition probability matrix has 1 rows full of 0s. Please set fill_empty_classes=True to set diagonal elements for these rows to be 1 to make sure the matrix is stochastic. | ||||||||
""" | ||||||||
""" # noqa E501 | ||||||||
|
||||||||
P = np.asarray(P) | ||||||||
rows0 = (P.sum(axis=1) == 0).sum() | ||||||||
|
@@ -353,7 +353,10 @@ def mfpt(P, fill_empty_classes=False): | |||||||
|
||||||||
def var_fmpt_ergodic(p): | ||||||||
warn( | ||||||||
"var_fmpt_ergodic is deprecated. It will be replaced in giddy 2.5 with var_fmpt_ergodic", | ||||||||
( | ||||||||
"var_fmpt_ergodic is deprecated. It will be " | ||||||||
"replaced in giddy 2.5 with var_fmpt_ergodic" | ||||||||
), | ||||||||
DeprecationWarning, | ||||||||
stacklevel=2, | ||||||||
) | ||||||||
|
@@ -398,7 +401,7 @@ def var_mfpt_ergodic(p): | |||||||
k = P.shape[0] | ||||||||
A = _steady_state_ergodic(P) | ||||||||
A = np.tile(A, (k, 1)) | ||||||||
I = np.identity(k) | ||||||||
I = np.identity(k) # noqa E741 | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does # noqa E741 mean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||
Z = la.inv(I - P + A) | ||||||||
E = np.ones_like(Z) | ||||||||
D = np.diag(1.0 / np.diag(A)) | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,6 @@ | |
from .ergodic import steady_state, mfpt | ||
from .util import fill_empty_diagonals | ||
from .components import Graph | ||
from warnings import warn | ||
from scipy import stats | ||
from scipy.stats import rankdata | ||
from operator import gt | ||
|
@@ -282,12 +281,12 @@ def __init__(self, class_ids, classes=None, fill_empty_classes=False, summary=Tr | |
) | ||
print(*self.astates_indices, sep=", ") | ||
|
||
@property | ||
def mfpt(self): | ||
warn("self._mfpt is deprecated. Please use self._mfpt") | ||
if not hasattr(self, "_mfpt"): | ||
self._mfpt = mfpt(self.p, fill_empty_classes=True) | ||
return self._mfpt | ||
# @property | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this commented out? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Also, I am a bit confused on the need for two identical methods. Should one be removed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, I will make the change and add to the PR. Thank you! |
||
# def mfpt(self): | ||
# warn("self._mfpt is deprecated. Please use self._mfpt") | ||
# if not hasattr(self, "_mfpt"): | ||
# self._mfpt = mfpt(self.p, fill_empty_classes=True) | ||
# return self._mfpt | ||
|
||
@property | ||
def mfpt(self): | ||
|
@@ -708,7 +707,9 @@ class Spatial_Markov(object): | |
We can easily adjust this assigning `fill_empty_classes = True` when initializing | ||
`Spatial_Markov`. | ||
|
||
>>> sm = Spatial_Markov(rpci, w, cutoffs=cc, lag_cutoffs=cc, fill_empty_classes=True) | ||
>>> sm = Spatial_Markov( | ||
... rpci, w, cutoffs=cc, lag_cutoffs=cc, fill_empty_classes=True | ||
... ) | ||
>>> for p in sm.P: | ||
... print(p) | ||
[[0.96703297 0.03296703 0. 0. 0. ] | ||
|
@@ -1075,7 +1076,7 @@ def _maybe_classify(self, y, k, cutoffs): | |
|
||
|
||
def chi2(T1, T2): | ||
""" | ||
r""" | ||
chi-squared test of difference between two transition matrices. | ||
|
||
Parameters | ||
|
@@ -1849,7 +1850,7 @@ def summary(self, file_name=None, title="Markov Homogeneity Test"): | |
lead = "-" * width | ||
head = title.center(width) | ||
contents = [lead, head, lead] | ||
l = "Number of regimes: %d" % int(self.m) | ||
l = "Number of regimes: %d" % int(self.m) # noqa E741 | ||
k = "Number of classes: %d" % int(self.k) | ||
r = "Regime names: " | ||
r += ", ".join(regime_names) | ||
|
@@ -2085,13 +2086,13 @@ def sojourn_time(p, summary=True): | |
>>> sojourn_time(p) | ||
Sojourn times are infinite for absorbing states! In this Markov Chain, states [2] are absorbing states. | ||
array([ 2., 1., inf]) | ||
""" | ||
""" # noqa E501 | ||
|
||
p = np.asarray(p) | ||
if (p.sum(axis=1) == 0).sum() > 0: | ||
p = fill_empty_diagonals(p) | ||
|
||
markovchain = qe.MarkovChain(p) | ||
# markovchain = qe.MarkovChain(p) | ||
pii = p.diagonal() | ||
|
||
if not (1 - pii).all(): | ||
|
@@ -2213,7 +2214,8 @@ class GeoRank_Markov(Markov): | |
|
||
def __init__(self, y, fill_empty_classes=False, summary=True): | ||
y = np.asarray(y) | ||
n = y.shape[0] | ||
# n = y.shape[0] | ||
|
||
# resolve ties: All values are given a distinct rank, corresponding | ||
# to the order that the values occur in each cross section. | ||
ranks = np.array([rankdata(col, method="ordinal") for col in y.T]).T | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import unittest | ||
import numpy as np | ||
import pytest | ||
from ..sequence import Sequence | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does # noqa F401, E402 mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are codes telling
ruff
that those lines are not problems: