From 09b1d13903c803d0407a55d355d7d7ebf2c69810 Mon Sep 17 00:00:00 2001 From: Philip Stark Date: Sun, 17 Mar 2024 19:36:24 -0700 Subject: [PATCH 01/10] ENH: return random_allocation in the same order as the sample sizes passed to the function --- cryptorandom/sample.py | 14 +++++++------- cryptorandom/tests/test_sample.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cryptorandom/sample.py b/cryptorandom/sample.py index 13bab45..ef59c78 100644 --- a/cryptorandom/sample.py +++ b/cryptorandom/sample.py @@ -179,20 +179,20 @@ def random_allocation(a, sizes, replace=False, fast=False, p=None, method="sampl raise ValueError('sample sizes greater than population size') samples = [0] * len(sizes) - # sort sizes from smallest to largest - sizes.sort() - # get random samples for all the groups except the largest one - for i in range(len(sizes) - 1): + # get random samples for all the groups except the largest one. Work from smallest to largest for numerical stability + size_increasing_inx = argsort(sizes) + biggest = size_increasing_inx[-1] + for i in size_increasing_inx[:-1]: sam = random_sample(list(indices), sizes[i], replace, fast, p, method, prng) samples[i] = a[sam] if not replace: indices = set(indices) - set(sam) # get the sample for the largest group - if not replace and N == np.sum(sizes): + if (not replace) and N == np.sum(sizes) and fast: sam = list(indices) else: - sam = random_sample(list(indices), sizes[-1], replace, fast, p, method, prng) - samples[-1] = a[sam] + sam = random_sample(list(indices), sizes[biggest], replace, fast, p, method, prng) + samples[biggest] = a[sam] return samples diff --git a/cryptorandom/tests/test_sample.py b/cryptorandom/tests/test_sample.py index 7ccce34..c634dd1 100644 --- a/cryptorandom/tests/test_sample.py +++ b/cryptorandom/tests/test_sample.py @@ -316,7 +316,7 @@ def test_random_allocation(): samples = random_allocation(10, [5, 5], replace = False) assert all(x in np.arange(10) for x in samples[0]) assert all(x in np.arange(10) for x in samples[1]) - assert np.sum(samples) == np.sum(np.arange(10)) + assert set(samples[0]) + set(samples[1]) == set(np.arange(10)) # test with replacement a = [1, 2, 2, 3, 3] From e50315876eb04d4e625d912e241db69d6032505a Mon Sep 17 00:00:00 2001 From: Philip Stark Date: Tue, 26 Mar 2024 12:13:29 -0700 Subject: [PATCH 02/10] ENH: return random allocation in the requested order --- cryptorandom/sample.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cryptorandom/sample.py b/cryptorandom/sample.py index ef59c78..f859acd 100644 --- a/cryptorandom/sample.py +++ b/cryptorandom/sample.py @@ -186,7 +186,7 @@ def random_allocation(a, sizes, replace=False, fast=False, p=None, method="sampl sam = random_sample(list(indices), sizes[i], replace, fast, p, method, prng) samples[i] = a[sam] if not replace: - indices = set(indices) - set(sam) + indices = list(set(indices) - set(sam)) # get the sample for the largest group if (not replace) and N == np.sum(sizes) and fast: sam = list(indices) From cd7b7fa3cd439f7d78e5a50612887fe7d12007a7 Mon Sep 17 00:00:00 2001 From: Philip Stark Date: Sat, 19 Apr 2025 16:05:15 -0700 Subject: [PATCH 03/10] ENH: updated test of random_allocation() to keep order of sizes the same --- cryptorandom/tests/test_sample.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cryptorandom/tests/test_sample.py b/cryptorandom/tests/test_sample.py index c634dd1..21a5e94 100644 --- a/cryptorandom/tests/test_sample.py +++ b/cryptorandom/tests/test_sample.py @@ -313,10 +313,14 @@ def test_permute_by_index(): def test_random_allocation(): # test random allocation without replacement - samples = random_allocation(10, [5, 5], replace = False) - assert all(x in np.arange(10) for x in samples[0]) - assert all(x in np.arange(10) for x in samples[1]) - assert set(samples[0]) + set(samples[1]) == set(np.arange(10)) + samples = random_allocation(15, [6, 4, 5], replace = False) + assert len(samples[0]) == 6 + assert len(samples[1]) == 4 + assert len(samples[2]) == 5 + assert all(x in np.arange(15) for x in samples[0]) + assert all(x in np.arange(15) for x in samples[1]) + assert all(x in np.arange(15) for x in samples[2]) + assert set(samples[0]) + set(samples[1]) + set(samples[2]) == set(np.arange(15)) # test with replacement a = [1, 2, 2, 3, 3] From 9ec4cd43a0ad844b8f374320730ea7d9762f4dcb Mon Sep 17 00:00:00 2001 From: Philip Stark Date: Wed, 23 Apr 2025 09:41:34 -0700 Subject: [PATCH 04/10] ENH: keep samples in the size order requested in random_allocation --- cryptorandom/sample.py | 2 +- cryptorandom/tests/test_sample.py | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/cryptorandom/sample.py b/cryptorandom/sample.py index f859acd..54b8bbc 100644 --- a/cryptorandom/sample.py +++ b/cryptorandom/sample.py @@ -180,7 +180,7 @@ def random_allocation(a, sizes, replace=False, fast=False, p=None, method="sampl samples = [0] * len(sizes) # get random samples for all the groups except the largest one. Work from smallest to largest for numerical stability - size_increasing_inx = argsort(sizes) + size_increasing_inx = np.argsort(sizes) biggest = size_increasing_inx[-1] for i in size_increasing_inx[:-1]: sam = random_sample(list(indices), sizes[i], replace, fast, p, method, prng) diff --git a/cryptorandom/tests/test_sample.py b/cryptorandom/tests/test_sample.py index 21a5e94..e1e2d2a 100644 --- a/cryptorandom/tests/test_sample.py +++ b/cryptorandom/tests/test_sample.py @@ -320,7 +320,7 @@ def test_random_allocation(): assert all(x in np.arange(15) for x in samples[0]) assert all(x in np.arange(15) for x in samples[1]) assert all(x in np.arange(15) for x in samples[2]) - assert set(samples[0]) + set(samples[1]) + set(samples[2]) == set(np.arange(15)) + assert set(samples[0]) | set(samples[1]) | set(samples[2]) == set(np.arange(15)) # test with replacement a = [1, 2, 2, 3, 3] @@ -328,8 +328,6 @@ def test_random_allocation(): samples = random_allocation(a, sizes, replace = True) assert all(x in a for x in samples[0]) assert all(x in a for x in samples[1]) - # test that smallest sample is sample first - assert len(samples[0]) == np.min(sizes) # test when sum of sample sizes is less than population size a = [1, 2, 2, 3, 3] From 6912bde663000f0b65312415a3952f96672e04c3 Mon Sep 17 00:00:00 2001 From: Philip Stark Date: Wed, 23 Apr 2025 09:52:34 -0700 Subject: [PATCH 05/10] BUG: updte python version in .github yaml --- .github/workflows/coverage.yml | 2 +- .github/workflows/test.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 8c88b83..8b285bb 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -11,7 +11,7 @@ jobs: runs-on: Ubuntu-latest strategy: matrix: - python-version: [3.9] + python-version: [3.12] steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fe5df45..8493da9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: runs-on: Ubuntu-latest strategy: matrix: - python-version: [3.7, 3.8, 3.9] + python-version: [3.10, 3.11, 3.12] steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} @@ -41,7 +41,7 @@ jobs: runs-on: macOS-latest strategy: matrix: - python-version: [3.7, 3.8, 3.9] + python-version: [3.10, 3.11, 3.12] steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} From b97dab0b77ddcc56111092cf22645d32a6e5702a Mon Sep 17 00:00:00 2001 From: Philip Stark Date: Wed, 23 Apr 2025 09:57:18 -0700 Subject: [PATCH 06/10] BUG: updte python version in .github yaml --- .github/workflows/test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8493da9..b9d2c54 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: runs-on: Ubuntu-latest strategy: matrix: - python-version: [3.10, 3.11, 3.12] + python-version: [3.11, 3.12] steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} @@ -41,7 +41,7 @@ jobs: runs-on: macOS-latest strategy: matrix: - python-version: [3.10, 3.11, 3.12] + python-version: [3.11, 3.12] steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} @@ -70,7 +70,7 @@ jobs: runs-on: windows-latest strategy: matrix: - python-version: [3.7, 3.8, 3.9] + python-version: [3.11, 3.12] steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} From 21d46c1e961394d846409c1ac929f23e9fc07774 Mon Sep 17 00:00:00 2001 From: Philip Stark Date: Wed, 23 Apr 2025 10:06:41 -0700 Subject: [PATCH 07/10] BUG: updte requirements to later versions of sphinx, numpy, etc. --- requirements/default.txt | 4 ++-- requirements/doc.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/requirements/default.txt b/requirements/default.txt index 3f11151..316cf4f 100644 --- a/requirements/default.txt +++ b/requirements/default.txt @@ -1,2 +1,2 @@ -numpy>=1.20 -scipy>=1.6 +numpy>=2.2 +scipy>=1.15 diff --git a/requirements/doc.txt b/requirements/doc.txt index 2c4d2ac..9ae5b49 100644 --- a/requirements/doc.txt +++ b/requirements/doc.txt @@ -1,2 +1,2 @@ -Sphinx~=4.0 +Sphinx>=8.0 numpydoc>=1.1 From 085e936aeeaa07068ebd2b6d46515442126c9eb8 Mon Sep 17 00:00:00 2001 From: Philip Stark Date: Wed, 23 Apr 2025 10:10:42 -0700 Subject: [PATCH 08/10] ENH: updte numpy version requirement --- requirements/default.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/default.txt b/requirements/default.txt index 316cf4f..29dc852 100644 --- a/requirements/default.txt +++ b/requirements/default.txt @@ -1,2 +1,2 @@ -numpy>=2.2 +numpy>=2.0 scipy>=1.15 From ba97cfeafbbbbc3fd670960a54b03d1bbc18a542 Mon Sep 17 00:00:00 2001 From: Philip Stark Date: Wed, 23 Apr 2025 10:14:45 -0700 Subject: [PATCH 09/10] ENH: updte scipy version requirement --- requirements/default.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/default.txt b/requirements/default.txt index 29dc852..af95058 100644 --- a/requirements/default.txt +++ b/requirements/default.txt @@ -1,2 +1,2 @@ numpy>=2.0 -scipy>=1.15 +scipy>=1.12 From 8a748b282c28b94e8fd01a520b30cdecbee934f3 Mon Sep 17 00:00:00 2001 From: Philip Stark Date: Wed, 23 Apr 2025 10:19:09 -0700 Subject: [PATCH 10/10] ENH: updte sphinx y version requirement --- requirements/doc.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/doc.txt b/requirements/doc.txt index 9ae5b49..0e7511a 100644 --- a/requirements/doc.txt +++ b/requirements/doc.txt @@ -1,2 +1,2 @@ -Sphinx>=8.0 +Sphinx>=5.0 numpydoc>=1.1