From 3ea992c61c3642b2c5f174c8ed96e64265870792 Mon Sep 17 00:00:00 2001 From: Adam Ormondroyd <52655393+AdamOrmondroyd@users.noreply.github.com> Date: Sat, 2 Mar 2024 00:35:10 +0000 Subject: [PATCH] Cast `root` to `str` to allow e.g. a `pathlib.Path` object to be used (#358) * cast root to string in case it is a path * move import to top * bump version to 2.6.1 --------- Co-authored-by: Will Handley --- README.rst | 2 +- anesthetic/_version.py | 2 +- anesthetic/read/chain.py | 3 ++- tests/test_reader.py | 7 +++++++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 5194d77f..a21078ae 100644 --- a/README.rst +++ b/README.rst @@ -2,7 +2,7 @@ anesthetic: nested sampling post-processing =========================================== :Authors: Will Handley and Lukas Hergt -:Version: 2.7.2 +:Version: 2.7.3 :Homepage: https://github.com/handley-lab/anesthetic :Documentation: http://anesthetic.readthedocs.io/ diff --git a/anesthetic/_version.py b/anesthetic/_version.py index 63bdf07f..66eabed2 100644 --- a/anesthetic/_version.py +++ b/anesthetic/_version.py @@ -1 +1 @@ -__version__ = '2.7.2' +__version__ = '2.7.3' diff --git a/anesthetic/read/chain.py b/anesthetic/read/chain.py index c0a3a092..3b28a743 100644 --- a/anesthetic/read/chain.py +++ b/anesthetic/read/chain.py @@ -26,7 +26,7 @@ def read_chains(root, *args, **kwargs): Parameters ---------- - root : str + root : str, pathlib.Path root name for reading files *args, **kwargs: @@ -39,6 +39,7 @@ def read_chains(root, *args, **kwargs): :class:`anesthetic.samples.MCMCSamples` depending on auto-detection """ + root = str(root) if 'burn_in' in kwargs: raise KeyError( "This is anesthetic 1.0 syntax. The `burn_in` keyword is no " diff --git a/tests/test_reader.py b/tests/test_reader.py index 05f7ec7f..134b2cac 100644 --- a/tests/test_reader.py +++ b/tests/test_reader.py @@ -1,5 +1,6 @@ import anesthetic.examples._matplotlib_agg # noqa: F401 import os +from pathlib import Path import pytest import numpy as np from numpy.testing import assert_array_equal, assert_array_almost_equal @@ -300,3 +301,9 @@ def test_hdf5(tmp_path, root): samples_ = read_hdf(filename, key) assert_frame_equal(samples_, samples) assert type(samples_) is type(samples) + + +@pytest.mark.parametrize('root', ['pc', 'gd']) +def test_path(root): + base_dir = Path("./tests/example_data") + read_chains(base_dir / root)