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

Test suite tidy #319

Merged
merged 24 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
075ab77
Removed fastkde from test_samples
williamjameshandley Jul 25, 2023
4594e65
bump version to 2.1.1
williamjameshandley Jul 25, 2023
0dc3fe8
Added bump version script for convenience
williamjameshandley Jul 25, 2023
e0db4cc
Moved astropy to skip rather than fail, and marked all fastkde
williamjameshandley Jul 25, 2023
182b8b7
removed erroneous kind check
williamjameshandley Jul 25, 2023
eccf259
Added utils
williamjameshandley Jul 25, 2023
042b517
More updates for other conditional skipping
williamjameshandley Jul 25, 2023
380f61b
Changed getdist to be an importerror
williamjameshandley Jul 25, 2023
a1d3bda
Moved importerrors into the function itself
williamjameshandley Jul 25, 2023
12e88ff
bump version to 2.1.2
williamjameshandley Jul 26, 2023
d9df05a
Merge branch 'master' into test_suite_cleaning
williamjameshandley Jul 26, 2023
49b236c
Merge branch 'master' into test_suite_cleaning
lukashergt Jul 27, 2023
8e1e427
update merged changes to new `fastkde_skipif` functionality
lukashergt Jul 27, 2023
0b3538e
Merge branch 'master' into test_suite_cleaning
lukashergt Jul 31, 2023
84201e9
Merge branch 'master' into test_suite_cleaning
williamjameshandley Aug 1, 2023
833cc75
Corrected merge of fastkde keys
williamjameshandley Aug 1, 2023
3d4af45
Caught importerror
williamjameshandley Aug 1, 2023
870e0a2
Renamed skipif functions
williamjameshandley Aug 1, 2023
ff295fe
Converted xfails to xskips
williamjameshandley Aug 3, 2023
df66faf
Reverted tests
williamjameshandley Aug 3, 2023
cbab943
Reordered fastkde
williamjameshandley Aug 3, 2023
a6b690d
converted xfails to skips
williamjameshandley Aug 3, 2023
9e159df
Removed final xskips
williamjameshandley Aug 3, 2023
8c8b721
reinstated xskips
williamjameshandley Aug 3, 2023
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
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
anesthetic: nested sampling post-processing
===========================================
:Authors: Will Handley and Lukas Hergt
:Version: 2.1.1
:Version: 2.1.2
:Homepage: https://github.com/handley-lab/anesthetic
:Documentation: http://anesthetic.readthedocs.io/

Expand Down
2 changes: 1 addition & 1 deletion anesthetic/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.1.1'
__version__ = '2.1.2'
5 changes: 4 additions & 1 deletion anesthetic/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ def to_getdist(samples):
getdist_samples : :class:`getdist.mcsamples.MCSamples`
getdist equivalent samples
"""
import getdist
try:
import getdist
except ModuleNotFoundError:
raise ImportError("You need to install getdist to use this function")
labels = np.char.strip(samples.get_labels().astype(str), '$')
samples = samples.drop_labels()
ranges = samples.agg(['min', 'max']).T.apply(tuple, axis=1).to_dict()
Expand Down
17 changes: 6 additions & 11 deletions anesthetic/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@
from scipy.special import erf
from matplotlib.gridspec import GridSpec, GridSpecFromSubplotSpec
from matplotlib.axes import Axes
try:
from astropy.visualization import hist
except ImportError:
pass
try:
from anesthetic.kde import fastkde_1d, fastkde_2d
except ImportError:
pass
import matplotlib.cbook as cbook
import matplotlib.lines as mlines
from matplotlib.ticker import MaxNLocator, AutoMinorLocator
Expand Down Expand Up @@ -767,8 +759,9 @@ def fastkde_plot_1d(ax, data, *args, **kwargs):
q = quantile_plot_interval(q=q)

try:
from anesthetic.kde import fastkde_1d
x, p, xmin, xmax = fastkde_1d(data, xmin, xmax)
except NameError:
except ImportError:
raise ImportError("You need to install fastkde to use fastkde")
p /= p.max()
i = ((x > quantile(x, q[0], p)) & (x < quantile(x, q[-1], p)))
Expand Down Expand Up @@ -969,10 +962,11 @@ def hist_plot_1d(ax, data, *args, **kwargs):

if type(bins) == str and bins in ['knuth', 'freedman', 'blocks']:
try:
from astropy.visualization import hist
h, edges, bars = hist(data, ax=ax, bins=bins,
range=(xmin, xmax), histtype=histtype,
color=color, *args, **kwargs)
except NameError:
except ImportError:
raise ImportError("You need to install astropy to use astropyhist")
else:
h, edges, bars = ax.hist(data, weights=weights, bins=bins,
Expand Down Expand Up @@ -1046,10 +1040,11 @@ def fastkde_contour_plot_2d(ax, data_x, data_y, *args, **kwargs):
kwargs.pop('q', None)

try:
from anesthetic.kde import fastkde_2d
x, y, pdf, xmin, xmax, ymin, ymax = fastkde_2d(data_x, data_y,
xmin=xmin, xmax=xmax,
ymin=ymin, ymax=ymax)
except NameError:
except ImportError:
raise ImportError("You need to install fastkde to use fastkde")

levels = iso_probability_contours(pdf, contours=levels)
Expand Down
5 changes: 1 addition & 4 deletions anesthetic/read/ultranest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
import os
import json
from anesthetic.samples import NestedSamples
try:
import h5py
except ImportError:
pass


def read_ultranest(root, *args, **kwargs):
Expand All @@ -23,6 +19,7 @@ def read_ultranest(root, *args, **kwargs):
num_params = len(labels)

filepath = os.path.join(root, 'results', 'points.hdf5')
import h5py
lukashergt marked this conversation as resolved.
Show resolved Hide resolved
with h5py.File(filepath, 'r') as fileobj:
points = fileobj['points']
_, ncols = points.shape
Expand Down
1 change: 1 addition & 0 deletions anesthetic/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ def plot_2d(self, axes=None, *args, **kwargs):
'kde_1d': {'diagonal': 'kde_1d'},
'kde_2d': {'lower': 'kde_2d'},
'hist': {'diagonal': 'hist_1d', 'lower': 'hist_2d'},
'fastkde': {'diagonal': 'fastkde_1d', 'lower': 'fastkde_2d'},
'hist_1d': {'diagonal': 'hist_1d'},
'hist_2d': {'lower': 'hist_2d'},
}
Expand Down
38 changes: 38 additions & 0 deletions bin/bump_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python
from utils import run
from packaging import version
import sys

vfile = "anesthetic/_version.py"
README = "README.rst"

current_version = run("cat", vfile)
current_version = current_version.split("=")[-1].strip().strip("'")
current_version = version.parse(current_version)

if len(sys.argv) > 1:
update_type = sys.argv[1]
else:
update_type = "micro"

major = current_version.major
minor = current_version.minor
micro = current_version.micro

if update_type == "micro":
micro+=1
elif update_type == "minor":
minor+=1
micro=0
elif update_type == "major":
major+=1
minor=0
micro=0

new_version = version.parse(f"{major}.{minor}.{micro}")

for f in [vfile, README]:
run("sed", "-i", f"s/{current_version}/{new_version}/g", f)

run("git", "add", vfile, README)
run("git", "commit", "-m", f"bump version to {new_version}")
10 changes: 2 additions & 8 deletions bin/check_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@
import sys
import subprocess
from packaging import version
from utils import unit_incremented
from utils import unit_incremented, run

vfile = "anesthetic/_version.py"
README = "README.rst"


def run(*args):
return subprocess.run(args, text=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE).stdout


current_version = run("cat", vfile)
current_version = current_version.split("=")[-1].strip().strip("'")

Expand Down
8 changes: 8 additions & 0 deletions bin/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
from packaging import version
import subprocess


def run(*args):
"""Run a bash command and return the output in Python."""
return subprocess.run(args, text=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE).stdout


def unit_incremented(a, b):
Expand Down
21 changes: 10 additions & 11 deletions tests/test_convert.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
from anesthetic import read_chains
from anesthetic.convert import to_getdist
from numpy.testing import assert_array_equal
from utils import getdist_mark_xfail


@getdist_mark_xfail
lukashergt marked this conversation as resolved.
Show resolved Hide resolved
def test_to_getdist():
try:
anesthetic_samples = read_chains('./tests/example_data/gd')
getdist_samples = to_getdist(anesthetic_samples)
anesthetic_samples = read_chains('./tests/example_data/gd')
getdist_samples = to_getdist(anesthetic_samples)

assert_array_equal(getdist_samples.samples, anesthetic_samples)
assert_array_equal(getdist_samples.weights,
anesthetic_samples.get_weights())
assert_array_equal(getdist_samples.samples, anesthetic_samples)
assert_array_equal(getdist_samples.weights,
anesthetic_samples.get_weights())

for param, p in zip(getdist_samples.getParamNames().names,
anesthetic_samples.drop_labels().columns):
for param, p in zip(getdist_samples.getParamNames().names,
anesthetic_samples.drop_labels().columns):

assert param.name == p
except ModuleNotFoundError:
pass
assert param.name == p
18 changes: 4 additions & 14 deletions tests/test_gui.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import sys
import anesthetic.examples._matplotlib_agg # noqa: F401
from anesthetic import read_chains
import pytest
import pandas._testing as tm
try:
import h5py # noqa: F401
except ImportError:
pass
from utils import h5py_skipif


@pytest.fixture(autouse=True)
Expand All @@ -16,10 +12,8 @@ def close_figures_on_teardown():

@pytest.mark.parametrize('root', ["./tests/example_data/pc",
"./tests/example_data/mn",
"./tests/example_data/un"])
h5py_skipif("./tests/example_data/un")])
def test_gui(root):
if 'un' in root and 'h5py' not in sys.modules:
pytest.skip("`h5py` not in sys.modules, but needed for ultranest.")
samples = read_chains(root)
plotter = samples.gui()

Expand Down Expand Up @@ -65,10 +59,8 @@ def test_gui(root):

@pytest.mark.parametrize('root', ["./tests/example_data/pc",
"./tests/example_data/mn",
"./tests/example_data/un"])
h5py_skipif("./tests/example_data/un")])
def test_gui_params(root):
if 'un' in root and 'h5py' not in sys.modules:
pytest.skip("`h5py` not in sys.modules, but needed for ultranest.")
samples = read_chains(root)
params = samples.columns.get_level_values(0).to_list()
plotter = samples.gui()
Expand All @@ -80,10 +72,8 @@ def test_gui_params(root):

@pytest.mark.parametrize('root', ["./tests/example_data/pc",
"./tests/example_data/mn",
"./tests/example_data/un"])
h5py_skipif("./tests/example_data/un")])
def test_slider_reset_range(root):
if 'un' in root and 'h5py' not in sys.modules:
pytest.skip("`h5py` not in sys.modules, but needed for ultranest.")
plotter = read_chains(root).gui()
plotter.evolution.reset_range(-3, 3)
assert plotter.evolution.ax.get_xlim() == (-3.0, 3.0)
Loading
Loading