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
6 changes: 4 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
exclude: |
(?x)^(tests/data)
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
Expand All @@ -10,7 +12,7 @@ repos:
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.0
rev: v0.9.9
hooks:
- id: ruff
name: ruff check
Expand All @@ -24,7 +26,7 @@ repos:
name: ruff format
alias: format
- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.391
rev: v1.1.396
hooks:
- id: pyright
additional_dependencies: [cython, httpretty, numpy, pytest, setuptools]
4 changes: 4 additions & 0 deletions cryosparc/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ONE_MIB = 2**20
"""
Bytes in 1 mebibyte
"""
9 changes: 7 additions & 2 deletions cryosparc/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
from typing_extensions import Literal, SupportsIndex

from .column import Column
from .constants import ONE_MIB
from .core import Data, DsetType, Stream
from .dtype import (
NEVER_COMPRESS_FIELDS,
Expand Down Expand Up @@ -632,8 +633,12 @@ def _load_numpy(
):
import os

# disable mmap by setting CRYOSPARC_DATASET_MMAP=false
if os.getenv("CRYOSPARC_DATASET_MMAP", "true").lower() == "true" and isinstance(file, (str, PurePath)):
# disable mmap by setting CRYOSPARC_DATASET_MMAP=false or dataset is small
if (
os.getenv("CRYOSPARC_DATASET_MMAP", "true").lower() == "true"
and isinstance(file, (str, PurePath))
and os.stat(file).st_size > ONE_MIB
):
# Use mmap to avoid loading full record array into memory
# cast path to a string for older numpy/python
mmap_mode, f = "r", str(file)
Expand Down
4 changes: 1 addition & 3 deletions cryosparc/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -1272,8 +1272,6 @@ def add_output(
slots: List[SlotSpec] = ...,
passthrough: Optional[str] = ...,
title: Optional[str] = ...,
*,
alloc: Literal[None] = None,
) -> str: ...
@overload
def add_output(
Expand All @@ -1284,7 +1282,7 @@ def add_output(
passthrough: Optional[str] = ...,
title: Optional[str] = ...,
*,
alloc: Union[int, Dataset] = ...,
alloc: Union[int, Dataset],
) -> Dataset: ...
def add_output(
self,
Expand Down
3 changes: 1 addition & 2 deletions cryosparc/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

from . import __version__, mrc
from .command import CommandClient, CommandError, make_json_request, make_request
from .constants import ONE_MIB
from .dataset import DEFAULT_FORMAT, Dataset
from .job import ExternalJob, Job
from .project import Project
Expand All @@ -53,8 +54,6 @@
from .util import bopen, noopcontext, padarray, print_table, trimarray
from .workspace import Workspace

ONE_MIB = 2**20 # bytes in one mebibyte

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}")
"""Regular expression for matching CryoSPARC license IDs."""

Expand Down
Binary file added tests/data/4k_dataset.cs
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,10 @@ def test_allocate_many_together():
allocated.append(Dataset(1))
assert len(allocated) == 66_000
del allocated


def test_load_4k():
# Check that a 4kiB dataset (same as linux page size) loads correctly
# (numpy bug https://github.com/numpy/numpy/pull/27723 fixed in 2.2)
d = Dataset.load("tests/data/4k_dataset.cs")
assert len(d) == 0
Loading