Skip to content

Commit

Permalink
Compatibility with pandas >=2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jsspencer committed Dec 18, 2023
1 parent 7938040 commit 8e1988a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pyblock/blocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyblock/pd_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions pyblock/tests/test_pd_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,16 @@ 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")
] = "<---"
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):
Expand Down

0 comments on commit 8e1988a

Please sign in to comment.