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

Changes for pandas 2.1 #335

Merged
merged 32 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9bf9c7b
pandas have removed teardown method, use plt.close instead
AdamOrmondroyd Sep 8, 2023
2aa3370
something funky going on with loc and masks, first pass
AdamOrmondroyd Sep 8, 2023
d6061ec
version bump
AdamOrmondroyd Sep 8, 2023
b6bd8a1
restrict pandas version to <2.2.0
AdamOrmondroyd Sep 8, 2023
e2022fc
add extra space
AdamOrmondroyd Sep 8, 2023
3a57886
stick to ~=2.1 for now
AdamOrmondroyd Sep 8, 2023
da2e838
update workflows to use 3.9 as minimum requirement, and 3.11 for buil…
AdamOrmondroyd Sep 9, 2023
332d5e4
autoupdate docs
AdamOrmondroyd Sep 10, 2023
9a3bfd0
correct python version in minimum dependencies name
AdamOrmondroyd Sep 10, 2023
ff0a9a3
Merge branch 'master' into pandas21
AdamOrmondroyd Sep 12, 2023
ba7bf8e
cast filled in labels to same type as given labels
AdamOrmondroyd Sep 12, 2023
9468521
test removing autoclass from PlotAccessor
AdamOrmondroyd Sep 12, 2023
0d1ce5f
Revert "test removing autoclass from PlotAccessor"
AdamOrmondroyd Sep 12, 2023
f0d6494
try removing examples from PlotAccessor docstring
AdamOrmondroyd Sep 12, 2023
62b9218
remove the accidentally added doc `show-inheritance` stuff for select…
lukashergt Sep 13, 2023
5104cac
Merge branch 'master' into pandas21
lukashergt Sep 13, 2023
e3d245c
revert the cutting out of the examples section from the PlotAccessor …
lukashergt Sep 13, 2023
735f4bd
preload pandas for autodoc for examples in docstrings
lukashergt Sep 13, 2023
43c5be5
move PlotAccessor stuff from samples into weighted_pandas, where it s…
lukashergt Sep 13, 2023
d60f312
also used anesthetic plotting for labelled_pandas
AdamOrmondroyd Sep 14, 2023
736e0ea
change mask instead
AdamOrmondroyd Sep 14, 2023
3f18b35
use .to_numpy() on other mask
AdamOrmondroyd Sep 15, 2023
45d08f8
some ilocs in test_plot.py due to label deprecation
AdamOrmondroyd Sep 20, 2023
51b0a0d
Merge branch 'master' into pandas21
AdamOrmondroyd Sep 22, 2023
4d92be4
return restriction to >=pandas2.0
AdamOrmondroyd Sep 22, 2023
6441764
['A'] instead of .iloc[0] so no line break needed
AdamOrmondroyd Sep 27, 2023
85a7d59
Merge branch 'master' into pandas21
AdamOrmondroyd Sep 27, 2023
84d514a
erroneous version to re trigger
williamjameshandley Sep 28, 2023
edf88de
Restored correct version number
williamjameshandley Sep 28, 2023
0dec83b
erroneous version to re trigger
williamjameshandley Sep 28, 2023
3d481d6
Restored correct version number
williamjameshandley Sep 28, 2023
0569afe
remove anesthetic PlotAccessor from labelled_pandas, so now just a pa…
AdamOrmondroyd Sep 29, 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
14 changes: 7 additions & 7 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.8'
python-version: '3.11'
- name: Upgrade pip and install doc requirements
run: |
python -m pip install --upgrade pip
Expand All @@ -56,7 +56,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.9', '3.10', '3.11']
extras: [true, false]
include:
- os: macos-latest
Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.9', '3.10', '3.11']
include:
- os: macos-latest
python-version: '3.11'
Expand Down Expand Up @@ -126,10 +126,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.8
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: 3.11
- name: Install pypa/build
run: python -m pip install build --user
- name: Build a binary wheel and a source tarball
Expand All @@ -146,10 +146,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.8
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: 3.9

- name: Install dependencies
run: |
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.8
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: 3.11
- name: Install pypa/build
run: python -m pip install build --user
- name: Build a binary wheel and a source tarball
Expand All @@ -53,10 +53,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.8
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: 3.11
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
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.3.1
:Version: 2.4.0
: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.3.1'
__version__ = '2.4.0'
3 changes: 2 additions & 1 deletion anesthetic/labelled_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ def get_labels_map(self, axis=0, fill=True):
labels_map = index.to_frame().droplevel(labs)[labs]
if fill:
replacement = labels_map.loc[labels_map == ''].index
labels_map.loc[labels_map == ''] = replacement
labels_map.loc[labels_map == ''] = replacement.astype(
labels_map.loc[labels_map != ''].dtype)
return labels_map
else:
return index.to_series()
Expand Down
3 changes: 2 additions & 1 deletion anesthetic/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def _process_docstring(doc):
" with fastkde package (DataFrame only)\n"
" - 'scatter_2d' : 2d scatter plot (DataFrame only)\n"
)
return doc[:i] + e + doc[i:]
j = doc.find(' Examples')
return doc[:i] + e + doc[i:j]


class PlotAccessor(_PlotAccessor):
Expand Down
2 changes: 1 addition & 1 deletion anesthetic/weighted_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def set_weights(self, weights, axis=0, inplace=False, level=None):
def _rand(self, axis=0):
"""Random number for consistent compression."""
seed = hash_pandas_object(self._get_axis(axis)).sum() % 2**32
with temporary_seed(seed):
with temporary_seed(int(seed)):
return np.random.rand(self.shape[axis])

def reset_index(self, level=None, drop=False, inplace=False,
Expand Down
19 changes: 19 additions & 0 deletions docs/source/anesthetic.read.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ anesthetic.read.hdf module
.. automodule:: anesthetic.read.hdf
:members:
:undoc-members:
:show-inheritance:
lukashergt marked this conversation as resolved.
Show resolved Hide resolved


anesthetic.read.multinest module
Expand All @@ -51,6 +52,15 @@ anesthetic.read.multinest module
:show-inheritance:


anesthetic.read.nestedfit module
--------------------------------

.. automodule:: anesthetic.read.nestedfit
:members:
:undoc-members:
:show-inheritance:


anesthetic.read.polychord module
--------------------------------

Expand All @@ -60,3 +70,12 @@ anesthetic.read.polychord module
:show-inheritance:


anesthetic.read.ultranest module
--------------------------------

.. automodule:: anesthetic.read.ultranest
:members:
:undoc-members:
:show-inheritance:


1 change: 1 addition & 0 deletions docs/source/anesthetic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,6 @@ anesthetic.weighted\_pandas module
.. automodule:: anesthetic.weighted_pandas
:members:
:undoc-members:
:show-inheritance:
lukashergt marked this conversation as resolved.
Show resolved Hide resolved


2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ requires-python = ">=3.8"
dependencies = [
"scipy",
"numpy",
"pandas~=2.0.0",
"pandas~=2.1.0",
"matplotlib>=3.6.1",
]
classifiers = [
Expand Down
5 changes: 3 additions & 2 deletions tests/test_gui.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import matplotlib.pyplot as plt
import anesthetic.examples._matplotlib_agg # noqa: F401
from anesthetic import read_chains
import pytest
import pandas._testing as tm
from utils import skipif_no_h5py


@pytest.fixture(autouse=True)
def close_figures_on_teardown():
tm.close()
yield
plt.close("all")


@pytest.mark.parametrize('root', ["./tests/example_data/pc",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
scatter_plot_2d, quantile_plot_interval,
basic_cmap, AxesSeries, AxesDataFrame)
from numpy.testing import assert_array_equal
import pandas._testing as tm

from matplotlib.axes import SubplotBase
from matplotlib.contour import ContourSet
Expand All @@ -25,7 +24,8 @@

@pytest.fixture(autouse=True)
def close_figures_on_teardown():
tm.close()
yield
plt.close("all")


def test_AxesObjects():
Expand Down
5 changes: 3 additions & 2 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest
import numpy as np
from numpy.testing import assert_array_equal, assert_array_almost_equal
import matplotlib.pyplot as plt
from anesthetic.testing import assert_frame_equal
from anesthetic import MCMCSamples, NestedSamples
from anesthetic import read_chains
Expand All @@ -12,14 +13,14 @@
from anesthetic.read.multinest import read_multinest
from anesthetic.read.ultranest import read_ultranest
from anesthetic.read.nestedfit import read_nestedfit
import pandas._testing as tm
from anesthetic.read.hdf import HDFStore, read_hdf
from utils import pytables_mark_xfail, h5py_mark_xfail, getdist_mark_skip


@pytest.fixture(autouse=True)
def close_figures_on_teardown():
tm.close()
yield
plt.close("all")


def test_read_getdist():
Expand Down
54 changes: 27 additions & 27 deletions tests/test_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
from numpy.testing import (assert_array_equal, assert_array_almost_equal,
assert_array_less, assert_allclose)
from pandas.testing import assert_frame_equal
import pandas._testing as tm
from matplotlib.colors import to_hex
from scipy.stats import ks_2samp, kstest, norm
from utils import skipif_no_fastkde, astropy_mark_xfail, fastkde_mark_skip


@pytest.fixture(autouse=True)
def close_figures_on_teardown():
tm.close()
yield
plt.close("all")


def test_build_samples():
Expand Down Expand Up @@ -1517,47 +1517,47 @@ def test_groupby_stats():
if 'chain' not in col:
for chain in [1, 2]:
mask = mcmc.chain == chain
assert_allclose(mcmc.loc[mask, col].mean(),
assert_allclose(mcmc.loc[mask][col].mean(),
lukashergt marked this conversation as resolved.
Show resolved Hide resolved
chains[col].mean().loc[chain])
assert_allclose(mcmc.loc[mask, col].std(),
assert_allclose(mcmc.loc[mask][col].std(),
chains[col].std().loc[chain])
assert_allclose(mcmc.loc[mask, col].median(),
assert_allclose(mcmc.loc[mask][col].median(),
chains[col].median().loc[chain])
assert_allclose(mcmc.loc[mask, col].var(),
assert_allclose(mcmc.loc[mask][col].var(),
chains[col].var().loc[chain])
assert_allclose(mcmc.loc[mask, col].kurt(),
assert_allclose(mcmc.loc[mask][col].kurt(),
chains[col].kurt().loc[chain])
assert_allclose(mcmc.loc[mask, col].kurtosis(),
assert_allclose(mcmc.loc[mask][col].kurtosis(),
chains[col].kurtosis().loc[chain])
assert_allclose(mcmc.loc[mask, col].skew(),
assert_allclose(mcmc.loc[mask][col].skew(),
chains[col].skew().loc[chain])
assert_allclose(mcmc.loc[mask, col].sem(),
assert_allclose(mcmc.loc[mask][col].sem(),
chains[col].sem().loc[chain])
assert_allclose(mcmc.loc[mask, col].cov(mcmc.loc[mask, col]),
chains[col].cov(mcmc.loc[mask, col])
assert_allclose(mcmc.loc[mask][col].cov(mcmc.loc[mask][col]),
chains[col].cov(mcmc.loc[mask][col])
.loc[chain])
assert_allclose(mcmc.loc[mask, col].corr(mcmc.loc[mask, col]),
chains[col].corr(mcmc.loc[mask, col])
assert_allclose(mcmc.loc[mask][col].corr(mcmc.loc[mask][col]),
chains[col].corr(mcmc.loc[mask][col])
.loc[chain])
q = np.random.rand()
assert_allclose(mcmc.loc[mask, col].quantile(q),
assert_allclose(mcmc.loc[mask][col].quantile(q),
chains[col].quantile(q).loc[chain])

group = chains[col].get_group(chain)
assert_allclose(mcmc.loc[mask, col].mean(), group.mean())
assert_allclose(mcmc.loc[mask, col].std(), group.std())
assert_allclose(mcmc.loc[mask, col].median(), group.median())
assert_allclose(mcmc.loc[mask, col].var(), group.var())
assert_allclose(mcmc.loc[mask, col].kurt(), group.kurt())
assert_allclose(mcmc.loc[mask, col].kurtosis(),
assert_allclose(mcmc.loc[mask][col].mean(), group.mean())
assert_allclose(mcmc.loc[mask][col].std(), group.std())
assert_allclose(mcmc.loc[mask][col].median(), group.median())
assert_allclose(mcmc.loc[mask][col].var(), group.var())
assert_allclose(mcmc.loc[mask][col].kurt(), group.kurt())
assert_allclose(mcmc.loc[mask][col].kurtosis(),
group.kurtosis())
assert_allclose(mcmc.loc[mask, col].skew(), group.skew())
assert_allclose(mcmc.loc[mask, col].sem(), group.sem())
assert_allclose(mcmc.loc[mask][col].skew(), group.skew())
assert_allclose(mcmc.loc[mask][col].sem(), group.sem())

assert_allclose(mcmc.loc[mask, col].cov(mcmc.loc[mask, col]),
group.cov(mcmc.loc[mask, col]))
assert_allclose(mcmc.loc[mask, col].corr(mcmc.loc[mask, col]),
group.corr(mcmc.loc[mask, col]))
assert_allclose(mcmc.loc[mask][col].cov(mcmc.loc[mask][col]),
group.cov(mcmc.loc[mask][col]))
assert_allclose(mcmc.loc[mask][col].corr(mcmc.loc[mask][col]),
group.corr(mcmc.loc[mask][col]))

sample = chains.sample(5)
assert len(sample) == 10
Expand Down
5 changes: 3 additions & 2 deletions tests/test_scripts.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import matplotlib.pyplot as plt
from anesthetic.scripts import gui
from bin.utils import unit_incremented
import pytest
import pandas._testing as tm


@pytest.fixture(autouse=True)
def close_figures_on_teardown():
tm.close()
yield
plt.close("all")


def test_gui():
Expand Down
4 changes: 2 additions & 2 deletions tests/test_weighted_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
from pandas.plotting._matplotlib.misc import (
scatter_matrix as orig_scatter_matrix
)
import pandas._testing as tm


@pytest.fixture(autouse=True)
def close_figures_on_teardown():
tm.close()
yield
plt.close("all")


@pytest.fixture
Expand Down