Skip to content

Commit 001faf1

Browse files
committed
Better handling of sqrt for resampling variance
1 parent 2b3d1be commit 001faf1

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎openpathsampling/numerics/resampling_statistics.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def std_df(objects, mean_x=None):
6666
n_obj = float(len(objects))
6767
sq = [o**2 for o in objects]
6868
variance = mean_df(sq) - mean_x**2
69-
return np.sqrt(variance)
69+
return variance.apply(lambda s: s.map(np.sqrt))
7070

7171
class ResamplingStatistics(object):
7272
"""

‎openpathsampling/tests/test_resampling_statistics.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ def test_std(self):
3636
)
3737
assert_frame_equal(std_df(self.inputs), expected_std)
3838

39+
def test_std_object_dtype(self):
40+
from openpathsampling.numerics.resampling_statistics import std_df
41+
object_inputs = [df.astype(object) for df in self.inputs]
42+
expected_std = pd.DataFrame(
43+
[[0.17677669529663689, 0.17677669529663689],
44+
[0.10606601717798207, 0.17677669529663689]],
45+
columns=['A', 'B'], index=['A', 'B']
46+
)
47+
assert_frame_equal(std_df(object_inputs), expected_std)
48+
3949
def test_initialization(self):
4050
stats = paths.numerics.ResamplingStatistics(
4151
function=lambda x: x,

0 commit comments

Comments
 (0)