Skip to content

Commit 60e0c3c

Browse files
authoredNov 2, 2023
Merge pull request #83 from StefRe/fix/pytest
TST: Update for pytest 7
2 parents 27a2d22 + cc0d51a commit 60e0c3c

14 files changed

+69
-74
lines changed
 

‎.github/workflows/check-test-coverage.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Setup Python
1414
uses: actions/setup-python@v2
1515
with:
16-
python-version: 3.8
16+
python-version: "3.11"
1717
- name: Generate coverage report
1818
run: |
1919
python -m pip install --upgrade pip

‎.github/workflows/python-runlinter.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ jobs:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- uses: actions/checkout@v2
18-
- name: Set up Python 3.8
18+
- name: Set up Python
1919
uses: actions/setup-python@v2
2020
with:
21-
python-version: 3.8
21+
python-version: "3.11"
2222
- name: Install dependencies
2323
run: |
2424
python -m pip install --upgrade pip

‎.github/workflows/python-runtests-img-comp.yml ‎.github/workflows/python-runtests-all.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ jobs:
1313
build:
1414

1515
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
python-version: ["3.8", "3.9", "3.10", "3.11"]
19+
1620
steps:
1721
- uses: actions/checkout@v2
18-
- name: Set up Python 3.8
22+
- name: Set up Python ${{ matrix.python-version }}
1923
uses: actions/setup-python@v2
2024
with:
21-
python-version: 3.8
25+
python-version: ${{ matrix.python-version }}
2226
- name: Install dependencies
2327
run: |
2428
python -m pip install --upgrade pip

‎.github/workflows/python-runtests-basic.yml

-33
This file was deleted.

‎README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# mpl-probscale
2+
23
Real probability scales for matplotlib
34

45
![Code Style](https://github.com/matplotlib/mpl-probscale/workflows/black/badge.svg)
@@ -7,7 +8,6 @@ Real probability scales for matplotlib
78
![Basic Tests](https://github.com/matplotlib/mpl-probscale/workflows/Basic%20unit%20tests/badge.svg)
89
![Image Comparisons](https://github.com/matplotlib/mpl-probscale/workflows/Image%20comparison%20tests/badge.svg)
910

10-
1111
[Sphinx Docs](http://matplotlib.org/mpl-probscale/)
1212

1313
## Installation
@@ -24,7 +24,7 @@ Official releases are available through the conda-forge channel or pip
2424

2525
This is a pure-python package, so building from source is easy on all platforms:
2626

27-
```
27+
```shell
2828
git clone git@github.com:matplotlib/mpl-probscale.git
2929
cd mpl-probscale
3030
pip install -e .
@@ -44,7 +44,6 @@ or
4444

4545
In the next release, this depedency will be made optional.
4646

47-
4847
## Quick start
4948

5049
Simply importing `probscale` lets you use probability scales in your matplotlib figures:

‎probscale/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@
33
from .viz import *
44
from .probscale import ProbScale
55

6+
67
scale.register_scale(ProbScale)
8+
9+
10+
__version__ = "0.2.6dev"
11+
__author__ = "Paul Hobson (Herrera Environmental Consultants)"
12+
__author_email__ = "phobson@herrerainc.com"

‎probscale/algo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def _estimate_from_fit(xhat, slope, intercept, xlog=False, ylog=False):
127127
xhat = numpy.asarray(xhat)
128128
if ylog:
129129
if xlog:
130-
yhat = numpy.exp(intercept) * xhat ** slope
130+
yhat = numpy.exp(intercept) * xhat**slope
131131
else:
132132
yhat = numpy.exp(intercept) * numpy.exp(slope) ** xhat
133133

‎probscale/formatters.py

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ def _sig_figs(cls, x, n, expthresh=5, forceint=False):
4545

4646
# check on the number provided
4747
elif x is not None and numpy.isfinite(x):
48-
4948
# check on the _sig_figs
5049
if n < 1:
5150
raise ValueError("number of sig figs (n) must be greater " "than zero")

‎probscale/probscale.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def _approx_erf(cls, x):
2929
3030
"""
3131

32-
guts = -(x ** 2) * (4.0 / numpy.pi + cls._A * x ** 2) / (1.0 + cls._A * x ** 2)
32+
guts = -(x**2) * (4.0 / numpy.pi + cls._A * x**2) / (1.0 + cls._A * x**2)
3333
with warnings.catch_warnings():
3434
warnings.filterwarnings("ignore", "invalid value encountered in sign")
3535
return numpy.sign(x) * numpy.sqrt(1.0 - numpy.exp(guts))
@@ -42,11 +42,11 @@ def _approx_inv_erf(cls, z):
4242
4343
"""
4444

45-
_b = (2 / numpy.pi / cls._A) + (0.5 * numpy.log(1 - z ** 2))
46-
_c = numpy.log(1 - z ** 2) / cls._A
45+
_b = (2 / numpy.pi / cls._A) + (0.5 * numpy.log(1 - z**2))
46+
_c = numpy.log(1 - z**2) / cls._A
4747
with warnings.catch_warnings():
4848
warnings.filterwarnings("ignore", "invalid value encountered in sign")
49-
return numpy.sign(z) * numpy.sqrt(numpy.sqrt(_b ** 2 - _c) - _b)
49+
return numpy.sign(z) * numpy.sqrt(numpy.sqrt(_b**2 - _c) - _b)
5050

5151
@classmethod
5252
def ppf(cls, q):

‎probscale/tests/test_algo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def test__bs_fit(plot_data, fitlogs, known_lo, known_hi):
121121

122122

123123
class Test__estimate_from_fit(object):
124-
def setup(self):
124+
def setup_method(self):
125125
self.x = numpy.arange(1, 11, 0.5)
126126
self.slope = 2
127127
self.intercept = 3.5

‎probscale/tests/test_probscale.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import warnings
23

34
import numpy
45
import matplotlib.pyplot as plt
@@ -120,16 +121,16 @@ def test_minimal_norm_cdf(mn, mn_input):
120121

121122

122123
def test_sign_with_nan_no_warning(mn):
123-
with pytest.warns(None) as record:
124+
with warnings.catch_warnings():
125+
warnings.simplefilter("error")
124126
res = mn._approx_erf(numpy.nan)
125-
assert not record
126127
assert numpy.isnan(res)
127128

128129

129130
def test_sign_with_nan_no_warning_inv(mn):
130-
with pytest.warns(None) as record:
131+
with warnings.catch_warnings():
132+
warnings.simplefilter("error")
131133
res = mn._approx_inv_erf(numpy.nan)
132-
assert not record
133134
assert numpy.isnan(res)
134135

135136

‎probscale/tests/test_viz.py

+19-4
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def plot_data():
7272

7373

7474
class Test_fit_line(object):
75-
def setup(self):
75+
def setup_method(self):
7676
self.data = numpy.array(
7777
[
7878
2.00,
@@ -454,7 +454,7 @@ def test_custom_xhat(self):
454454

455455

456456
class Test_plot_pos(object):
457-
def setup(self):
457+
def setup_method(self):
458458
self.data = numpy.arange(16)
459459

460460
self.known_type4 = numpy.array(
@@ -740,11 +740,11 @@ def test_probplot_prob(plot_data):
740740
fig, ax = plt.subplots()
741741
fig = viz.probplot(plot_data, ax=ax, problabel="Test xlabel", datascale="log")
742742
assert isinstance(fig, plt.Figure)
743-
return fig
744743

745744

746745
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TIGHT_TOLERANCE)
747746
def test_probplot_qq(plot_data):
747+
plt.close("all")
748748
fig, ax = plt.subplots()
749749
fig = viz.probplot(
750750
plot_data,
@@ -760,6 +760,7 @@ def test_probplot_qq(plot_data):
760760
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TIGHT_TOLERANCE)
761761
@pytest.mark.skipif(stats is None, reason="no scipy")
762762
def test_probplot_qq_dist(plot_data):
763+
plt.close("all")
763764
fig, ax = plt.subplots()
764765
norm = stats.norm(*stats.norm.fit(plot_data))
765766
fig = viz.probplot(
@@ -770,6 +771,7 @@ def test_probplot_qq_dist(plot_data):
770771

771772
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TIGHT_TOLERANCE)
772773
def test_probplot_pp(plot_data):
774+
plt.close("all")
773775
fig, ax = plt.subplots()
774776
scatter_kws = dict(
775777
color="b", linestyle="--", markeredgecolor="g", markerfacecolor="none"
@@ -792,6 +794,7 @@ def test_probplot_pp(plot_data):
792794
remove_text=True,
793795
)
794796
def test_probplot_prob_bestfit(plot_data):
797+
plt.close("all")
795798
fig, ax = plt.subplots()
796799
fig = viz.probplot(
797800
plot_data,
@@ -807,6 +810,7 @@ def test_probplot_prob_bestfit(plot_data):
807810

808811
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TIGHT_TOLERANCE)
809812
def test_probplot_prob_bestfit_exceedance(plot_data):
813+
plt.close("all")
810814
fig, ax = plt.subplots()
811815
fig = viz.probplot(
812816
plot_data,
@@ -823,6 +827,7 @@ def test_probplot_prob_bestfit_exceedance(plot_data):
823827

824828
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TIGHT_TOLERANCE)
825829
def test_probplot_qq_bestfit(plot_data):
830+
plt.close("all")
826831
fig, ax = plt.subplots()
827832
fig = viz.probplot(
828833
plot_data,
@@ -838,6 +843,7 @@ def test_probplot_qq_bestfit(plot_data):
838843

839844
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TIGHT_TOLERANCE)
840845
def test_probplot_pp_bestfit(plot_data):
846+
plt.close("all")
841847
fig, ax = plt.subplots()
842848
scatter_kws = {"marker": "s", "color": "red"}
843849
line_kws = {"linestyle": "--", "linewidth": 3}
@@ -858,6 +864,7 @@ def test_probplot_pp_bestfit(plot_data):
858864

859865
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TIGHT_TOLERANCE)
860866
def test_probplot_prob_probax_y(plot_data):
867+
plt.close("all")
861868
fig, ax = plt.subplots()
862869
fig = viz.probplot(
863870
plot_data, ax=ax, datalabel="Test xlabel", datascale="log", probax="y"
@@ -868,6 +875,7 @@ def test_probplot_prob_probax_y(plot_data):
868875

869876
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TIGHT_TOLERANCE)
870877
def test_probplot_qq_probax_y(plot_data):
878+
plt.close("all")
871879
fig, ax = plt.subplots()
872880
fig = viz.probplot(
873881
plot_data,
@@ -883,6 +891,7 @@ def test_probplot_qq_probax_y(plot_data):
883891

884892
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TIGHT_TOLERANCE)
885893
def test_probplot_pp_probax_y(plot_data):
894+
plt.close("all")
886895
fig, ax = plt.subplots()
887896
scatter_kws = dict(
888897
color="b", linestyle="--", markeredgecolor="g", markerfacecolor="none"
@@ -902,6 +911,7 @@ def test_probplot_pp_probax_y(plot_data):
902911

903912
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TIGHT_TOLERANCE)
904913
def test_probplot_prob_bestfit_probax_y(plot_data):
914+
plt.close("all")
905915
fig, ax = plt.subplots()
906916
fig = viz.probplot(
907917
plot_data,
@@ -918,6 +928,7 @@ def test_probplot_prob_bestfit_probax_y(plot_data):
918928

919929
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TIGHT_TOLERANCE)
920930
def test_probplot_qq_bestfit_probax_y(plot_data):
931+
plt.close("all")
921932
fig, ax = plt.subplots()
922933
fig = viz.probplot(
923934
plot_data,
@@ -934,6 +945,7 @@ def test_probplot_qq_bestfit_probax_y(plot_data):
934945

935946
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TIGHT_TOLERANCE)
936947
def test_probplot_pp_bestfit_probax_y(plot_data):
948+
plt.close("all")
937949
fig, ax = plt.subplots()
938950
scatter_kws = {"marker": "s", "color": "red"}
939951
line_kws = {"linestyle": "--", "linewidth": 3}
@@ -956,6 +968,7 @@ def test_probplot_pp_bestfit_probax_y(plot_data):
956968
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=LOOSE_TOLERANCE)
957969
@pytest.mark.skipif(stats is None, reason="no scipy")
958970
def test_probplot_beta_dist_best_fit_y(plot_data):
971+
plt.close("all")
959972
fig, (ax1, ax2) = plt.subplots(ncols=2)
960973
dist = stats.beta(3, 3)
961974
fig = viz.probplot(
@@ -991,6 +1004,7 @@ def test_probplot_beta_dist_best_fit_y(plot_data):
9911004
)
9921005
@pytest.mark.skipif(stats is None, reason="no scipy")
9931006
def test_probplot_beta_dist_best_fit_x(plot_data):
1007+
plt.close("all")
9941008
fig, (ax1, ax2) = plt.subplots(nrows=2)
9951009
dist = stats.beta(3, 3)
9961010
fig = viz.probplot(
@@ -1020,13 +1034,13 @@ def test_probplot_beta_dist_best_fit_x(plot_data):
10201034

10211035

10221036
def test_probplot_test_results(plot_data):
1037+
plt.close("all")
10231038
fig, ax = plt.subplots()
10241039
fig, results = viz.probplot(plot_data, return_best_fit_results=True)
10251040

10261041
assert isinstance(results, dict)
10271042
known_keys = sorted(["q", "x", "y", "xhat", "yhat", "res"])
10281043
assert sorted(list(results.keys())) == known_keys
1029-
return fig
10301044

10311045

10321046
@pytest.mark.parametrize("probax", ["x", "y"])
@@ -1048,6 +1062,7 @@ def test__set_prob_limits_x(probax, N, minval, maxval):
10481062

10491063
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TIGHT_TOLERANCE)
10501064
def test_probplot_color_and_label(plot_data):
1065+
plt.close("all")
10511066
fig, ax = plt.subplots()
10521067
fig = viz.probplot(plot_data, ax=ax, color="pink", label="A Top-Level Label")
10531068
ax.legend(loc="lower right")

‎setup.cfg

-7
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,5 @@ description-file = readme.md
33
license_file = LICENSE
44

55
[tool:pytest]
6-
pep8ignore =
7-
E501
8-
probscale/tests/test_*.py E241 E131
9-
docs/* ALL
10-
check_probscale.py ALL
11-
126
markers =
137
mpl_image_compare
14-
pep8

0 commit comments

Comments
 (0)
Please sign in to comment.