Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,12 @@ updates:
github-actions:
patterns:
- "*"
- package-ecosystem: uv
directory: "/"
schedule:
interval: monthly
open-pull-requests-limit: 1
groups:
uv:
patterns:
- "*"
15 changes: 15 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,18 @@ a demonstrated blocker requires otherwise.
- Before handing work back, summarize validation performed, anything not run,
and any data-integrity, numerical, compatibility, packaging, or release risk
that remains.

## Shared preferences and attribution

Codex and current Claude Code use this repository's `AGENTS.md` directly.
Personal defaults also live in `~/.codex/AGENTS.md`, imported by
`~/.claude/CLAUDE.md`. Keep repository instructions usable without those
personal files. More specific project rules take precedence.

- Never add AI attribution to commits, pull requests, or release notes: no
`Co-Authored-By:` trailer for an AI, no "Generated with ..." line, and no
other AI credit.
- Prefer focused changes, preserve useful TODO and debugging comments, and
report validation performed and work that remains.
- Do not publish packages, approve PyPI deployments, or push release tags
without an explicit request. Prepare artifacts and commands for the maintainer.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.0.1] - 2026-11-14

* Make `Hashdown` downloads (used by `example_file`) more robust: retry
network errors and HTTP 5xx responses up to three times with backoff, time
out stalled connections, and write each file under a temporary name so an
interrupted download never leaves a partial file in the cache.

* Correct 69 stale sample-file hashes to match the existing immutable source
commit, restoring example downloads without changing the sample data. Add
regression checks against generated data and distributed metadata.

* Require h5py 3.15.0 or later for the HDF5 extra on Python 3.14 and
later, while retaining the existing requirement on earlier Python versions.

## [1.0.0] - 2026-11-13

* Require Python 3.11.5 or later and refresh stable runtime and development
Expand Down
1 change: 0 additions & 1 deletion CLAUDE.md

This file was deleted.

8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "uv_build"

[project]
name = "pysnptools"
version = "1.0.0"
version = "1.0.1"
description = "PySnpTools"
readme = "README.md"
requires-python = ">=3.11.5"
Expand Down Expand Up @@ -67,7 +67,11 @@ Source = "https://github.com/fastlmm/PySnpTools"


[project.optional-dependencies]
hdf5 = ["h5py>=3.12.1"]
hdf5 = [
"h5py>=3.12.1; python_version < '3.14'",
# h5py 3.15.0 is the first release with Python 3.14 wheels.
"h5py>=3.15.0; python_version >= '3.14'",
]
bgen = ["cbgen>=1.0.6", "bgen-reader>=4.0.9"]
dev = [
"pytest",
Expand Down
36 changes: 36 additions & 0 deletions pysnptools/util/_example_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,42 @@ def example_file_synth(pattern, endswith=None):


class TestExampleFile(unittest.TestCase):
def test_generated_files_match_generator(self):
import numpy as np
from pysnptools.snpreader import Bed
from pysnptools.util import snp_gen

filename = example_file("tests/datasets/generate/gen1.*", endswith="*.bed")
downloaded = Bed(filename, count_A1=False).read()
generated = snp_gen(
fst=0, dfr=0.5, iid_count=200, sid_count=20, maf_low=0.05, seed=5
)
np.testing.assert_array_equal(downloaded.iid, generated.iid)
np.testing.assert_array_equal(downloaded.sid, generated.sid)
np.testing.assert_array_equal(downloaded.pos, generated.pos)
np.testing.assert_array_equal(downloaded.val, generated.val)

def test_distributed_files_match_metadata(self):
import numpy as np
from pysnptools.snpreader import Bed

filename = example_file(
"tests/datasets/distributed_bed_test1/chrom1.piece1of2.*",
endswith="*.bed",
)
downloaded = Bed(filename, count_A1=False).read()
metadata_filename = example_file(
"tests/datasets/distributed_bed_test1/metadata.npz"
)
with np.load(metadata_filename, allow_pickle=False) as metadata:
# This pinned piece contains markers 4 through 7 of the full dataset.
np.testing.assert_array_equal(downloaded.iid, metadata["_row"].astype(str))
np.testing.assert_array_equal(downloaded.sid, metadata["_col"][4:8].astype(str))
expected_positions = metadata["_col_property"][4:8].copy()
# Bed documents PLINK zero positions as missing; this metadata stores raw zeros.
expected_positions[expected_positions == 0] = np.nan
np.testing.assert_array_equal(downloaded.pos, expected_positions)

def test_doc_test(self):
import pysnptools.util._example_file as example_mod

Expand Down
3 changes: 3 additions & 0 deletions pysnptools/util/filecache/hashdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,12 @@ def _get_large_file(url, file, trust_local_files, length=16 * 1024):
return True
except HTTPError as e:
if e.code == 404:
e.close()
return False
if e.code < 500 or attempt == Hashdown._DOWNLOAD_ATTEMPTS:
raise
# Handled errors own response bodies just like successful responses.
e.close()
error = e
except (URLError, TimeoutError, ConnectionError, http.client.HTTPException) as e:
if attempt == Hashdown._DOWNLOAD_ATTEMPTS:
Expand Down
15 changes: 12 additions & 3 deletions pysnptools/util/filecache/test_hashdown_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ def _http_error(code):

class TestHashdownRetry(unittest.TestCase):
def setUp(self):
self.dir = tempfile.mkdtemp()
directory = tempfile.TemporaryDirectory()
self.addCleanup(directory.cleanup)
self.dir = directory.name
self.file = os.path.join(self.dir, "sub", "f.txt")
sleep = mock.patch.object(hashdown.time, "sleep")
self.sleep = sleep.start()
self.addCleanup(sleep.stop)

def _get(self, *responses):
calls = []
for response in responses:
if isinstance(response, (HTTPError, _Body)):
self.addCleanup(response.close)

def fake_urlopen(url, timeout=None):
calls.append(timeout)
Expand All @@ -63,14 +68,18 @@ def test_retries_transient_network_error(self):
self.sleep.assert_called_once_with(1)

def test_retries_server_error(self):
result, calls = self._get(_http_error(503), _http_error(502), _Body(b"ok"))
errors = [_http_error(503), _http_error(502)]
result, calls = self._get(*errors, _Body(b"ok"))
self.assertTrue(result)
self.assertTrue(all(error.closed for error in errors))
self.assertEqual(len(calls), 3)
self.assertEqual([c.args[0] for c in self.sleep.call_args_list], [1, 2])

def test_404_returns_false_without_retry(self):
result, calls = self._get(_http_error(404))
error = _http_error(404)
result, calls = self._get(error)
self.assertFalse(result)
self.assertTrue(error.closed)
self.assertEqual(len(calls), 1)
self.sleep.assert_not_called()

Expand Down
Loading
Loading