Skip to content

Commit d9e3a09

Browse files
committed
Merge remote-tracking branch 'origin/release-v4.7' into develop
2 parents 19945e5 + f5d7bf4 commit d9e3a09

File tree

6 files changed

+19
-6
lines changed

6 files changed

+19
-6
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# See https://pre-commit.com for more information
22
# See https://pre-commit.com/hooks.html for more hooks
3+
exclude: |
4+
(?x)^(tests/data)
35
repos:
46
- repo: https://github.com/pre-commit/pre-commit-hooks
57
rev: v5.0.0
@@ -10,7 +12,7 @@ repos:
1012
- id: check-yaml
1113
- id: check-added-large-files
1214
- repo: https://github.com/astral-sh/ruff-pre-commit
13-
rev: v0.9.0
15+
rev: v0.9.9
1416
hooks:
1517
- id: ruff
1618
name: ruff check
@@ -24,7 +26,7 @@ repos:
2426
name: ruff format
2527
alias: format
2628
- repo: https://github.com/RobertCraigie/pyright-python
27-
rev: v1.1.391
29+
rev: v1.1.396
2830
hooks:
2931
- id: pyright
3032
additional_dependencies:

cryosparc/dataset/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151

5252
import numpy as n
5353

54+
from ..constants import ONE_MIB
5455
from ..errors import DatasetLoadError
5556
from ..stream import AsyncReadable, Streamable
5657
from ..util import bopen, default_rng, random_integers, u32bytesle, u32intle
@@ -635,8 +636,12 @@ def _load_numpy(
635636
):
636637
import os
637638

638-
# disable mmap by setting CRYOSPARC_DATASET_MMAP=false
639-
if os.getenv("CRYOSPARC_DATASET_MMAP", "true").lower() == "true" and isinstance(file, (str, PurePath)):
639+
# disable mmap by setting CRYOSPARC_DATASET_MMAP=false or dataset is small
640+
if (
641+
os.getenv("CRYOSPARC_DATASET_MMAP", "true").lower() == "true"
642+
and isinstance(file, (str, PurePath))
643+
and os.stat(file).st_size > ONE_MIB
644+
):
640645
# Use mmap to avoid loading full record array into memory
641646
# cast path to a string for older numpy/python
642647
mmap_mode, f = "r", str(file)

cryosparc/dataset/core.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Data:
5151
def ncol(self) -> int: ...
5252
def nrow(self) -> int: ...
5353
def key(self, index: int) -> str: ...
54-
def type(self, field: str) -> int: ...
54+
def type(self, field: str) -> DsetType: ...
5555
def has(self, field: str) -> bool: ...
5656
def addrows(self, num: int) -> None: ...
5757
def addcol_scalar(self, field: str, dtype: int) -> None: ...

cryosparc/tools.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
assert model_registry
6161
registry.finalize() # no more models may be registered after this
6262

63-
ONE_MIB = 2**20 # bytes in one mebibyte
6463

6564
LICENSE_REGEX = re.compile(r"[a-f\d]{8}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{12}")
6665
"""Regular expression for matching CryoSPARC license IDs."""

tests/data/4k_dataset.cs

4 KB
Binary file not shown.

tests/test_dataset.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,3 +394,10 @@ def test_allocate_many_together():
394394
allocated.append(Dataset(1))
395395
assert len(allocated) == 66_000
396396
del allocated
397+
398+
399+
def test_load_4k():
400+
# Check that a 4kiB dataset (same as linux page size) loads correctly
401+
# (numpy bug https://github.com/numpy/numpy/pull/27723 fixed in 2.2)
402+
d = Dataset.load("tests/data/4k_dataset.cs")
403+
assert len(d) == 0

0 commit comments

Comments
 (0)