From 8e1988a6f94c76673ff0c77b79647c87f094d5a7 Mon Sep 17 00:00:00 2001 From: James Spencer Date: Mon, 18 Dec 2023 20:33:14 +0000 Subject: [PATCH] Compatibility with pandas >=2.0 --- pyblock/blocking.py | 4 ++-- pyblock/pd_utils.py | 2 +- pyblock/tests/test_pd_utils.py | 5 ++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pyblock/blocking.py b/pyblock/blocking.py index bbd0403..3a6a25c 100644 --- a/pyblock/blocking.py +++ b/pyblock/blocking.py @@ -106,8 +106,8 @@ def reblock(data, rowvar=1, ddof=None, weights=None): if weights is None: nsamp = data_len - mean = numpy.array(numpy.mean(data, axis=axis)) - cov = numpy.cov(data, rowvar=rowvar, ddof=ddof) + mean = numpy.array(numpy.mean(data, axis=axis)).reshape(nvar) + cov = numpy.cov(data, rowvar=rowvar, ddof=ddof).reshape((nvar, nvar)) else: mean, tot_weight = numpy.average( data, axis=axis, weights=weights, returned=True diff --git a/pyblock/pd_utils.py b/pyblock/pd_utils.py index 70f39b1..e5704ce 100644 --- a/pyblock/pd_utils.py +++ b/pyblock/pd_utils.py @@ -159,7 +159,7 @@ def optimal_block(block_sub_info): ] if not any(opt_cols): raise ValueError("No optimal block data") - iterator = block_sub_info.loc[:, opt_cols].iteritems() + iterator = block_sub_info.loc[:, opt_cols].items() opt = -1 for name, col in iterator: diff --git a/pyblock/tests/test_pd_utils.py b/pyblock/tests/test_pd_utils.py index bf80655..9d841d5 100644 --- a/pyblock/tests/test_pd_utils.py +++ b/pyblock/tests/test_pd_utils.py @@ -56,9 +56,8 @@ def test_pdblock_opt(self): self.assertEqual( pyblock.pd_utils.optimal_block(reblock), tests_base.reblock_1D_opt[0] ) - opt = reblock[("data", "optimal block")] self.assertEqual( - pyblock.pd_utils.optimal_block(opt), tests_base.reblock_1D_opt[0] + pyblock.pd_utils.optimal_block(reblock), tests_base.reblock_1D_opt[0] ) reblock.loc[ tests_base.reblock_1D_opt[0] - 1, ("data", "optimal block") @@ -66,7 +65,7 @@ def test_pdblock_opt(self): with self.assertRaises(ValueError): pyblock.pd_utils.optimal_block(reblock) reblock[("data", "optimal block")] = "" - self.assertEqual(pyblock.pd_utils.optimal_block(opt), float("inf")) + self.assertEqual(pyblock.pd_utils.optimal_block(reblock), float("inf")) self.assertTrue(pyblock.pd_utils.reblock_summary(reblock).empty) def test_weighted_pdblock(self):