Skip to content

Commit aadce8b

Browse files
ArmavicaricardoV94
authored andcommitted
Fix RUF007 (itertools.pairwise)
1 parent 923ec2f commit aadce8b

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

pymc/distributions/mixture.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
import itertools
1415
import warnings
1516

1617
import numpy as np
@@ -480,7 +481,7 @@ def transform_warning():
480481
transform.backward(value, *component.owner.inputs)
481482
for transform, component in zip(default_transforms, components)
482483
]
483-
for expr1, expr2 in zip(backward_expressions[:-1], backward_expressions[1:]):
484+
for expr1, expr2 in itertools.pairwise(backward_expressions):
484485
if not equal_computations([expr1], [expr2]):
485486
transform_warning()
486487
return None

tests/distributions/test_discrete.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import functools as ft
16+
import itertools
1617
import sys
1718
import warnings
1819

@@ -76,7 +77,7 @@ def invlogit(x, eps=sys.float_info.epsilon):
7677

7778
def orderedlogistic_logpdf(value, eta, cutpoints):
7879
c = np.concatenate(([-np.inf], cutpoints, [np.inf]))
79-
ps = np.array([invlogit(eta - cc) - invlogit(eta - cc1) for cc, cc1 in zip(c[:-1], c[1:])])
80+
ps = np.array([invlogit(eta - cc) - invlogit(eta - cc1) for cc, cc1 in itertools.pairwise(c)])
8081
p = ps[value]
8182
return np.where(np.all(ps >= 0), np.log(p), -np.inf)
8283

@@ -87,7 +88,7 @@ def invprobit(x):
8788

8889
def orderedprobit_logpdf(value, eta, cutpoints):
8990
c = np.concatenate(([-np.inf], cutpoints, [np.inf]))
90-
ps = np.array([invprobit(eta - cc) - invprobit(eta - cc1) for cc, cc1 in zip(c[:-1], c[1:])])
91+
ps = np.array([invprobit(eta - cc) - invprobit(eta - cc1) for cc, cc1 in itertools.pairwise(c)])
9192
p = ps[value]
9293
return np.where(np.all(ps >= 0), np.log(p), -np.inf)
9394

0 commit comments

Comments
 (0)