From cc92c4de9aec1d22e669cca49d337501d8bbe3e7 Mon Sep 17 00:00:00 2001 From: Younes Strittmatter Date: Tue, 23 Jul 2024 11:47:53 -0400 Subject: [PATCH] feat: reindex conditions in random sampling --- src/autora/experimentalist/random.py | 30 ++++++++++++++++------------ 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/autora/experimentalist/random.py b/src/autora/experimentalist/random.py index b4101adf..6deffb57 100644 --- a/src/autora/experimentalist/random.py +++ b/src/autora/experimentalist/random.py @@ -157,25 +157,29 @@ def sample( >>> import pandas as pd >>> sample( ... pd.DataFrame({"x": range(100, 200)}), num_samples=5, random_state=180) - x - 67 167 - 71 171 - 64 164 - 63 163 - 96 196 + x + 0 167 + 1 171 + 2 164 + 3 163 + 4 196 From a list (returns a DataFrame): >>> sample(range(1000), num_samples=5, random_state=180) - 0 - 270 270 - 908 908 - 109 109 - 331 331 - 978 978 + 0 + 0 270 + 1 908 + 2 109 + 3 331 + 4 978 """ conditions_ = pd.DataFrame(conditions) return pd.DataFrame.sample( - conditions_, random_state=random_state, n=num_samples, replace=replace + conditions_, + random_state=random_state, + n=num_samples, + replace=replace, + ignore_index=True, )