Skip to content

Commit

Permalink
Merge branch 'main' into read_existing_refs
Browse files Browse the repository at this point in the history
  • Loading branch information
norlandrhagen committed Oct 11, 2024
2 parents be709df + 2d66e88 commit 8d53227
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 14 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ jobs:
conda env list
conda list
- name: Type check
run: |
mypy virtualizarr
- name: Running Tests
run: |
python -m pytest ./virtualizarr --run-network-tests --cov=./ --cov-report=xml --verbose
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/typing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Typing

on:
push:
branches: [ "main" ]
paths-ignore:
- 'docs/**'
pull_request:
branches: [ "main" ]
paths-ignore:
- 'docs/**'
schedule:
- cron: "0 0 * * *"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
mypy:
name: mypy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'

- name: Install deps
run: |
# We need to test optional dep to add all the library stubs
pip install -e '.[test]'
- name: Type check
run: |
mypy virtualizarr
21 changes: 14 additions & 7 deletions virtualizarr/manifests/array_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import TYPE_CHECKING, Callable, Iterable
from typing import TYPE_CHECKING, Any, Callable, Iterable, cast

import numpy as np

Expand Down Expand Up @@ -217,9 +217,12 @@ def stack(
new_shape.insert(axis, length_along_new_stacked_axis)

# do stacking of entries in manifest
stacked_paths = np.stack(
[arr.manifest._paths for arr in arrays],
axis=axis,
stacked_paths = cast( # `np.stack` apparently is type hinted as if the output could have Any dtype
np.ndarray[Any, np.dtypes.StringDType],
np.stack(
[arr.manifest._paths for arr in arrays],
axis=axis,
),
)
stacked_offsets = np.stack(
[arr.manifest._offsets for arr in arrays],
Expand Down Expand Up @@ -296,10 +299,14 @@ def broadcast_to(x: "ManifestArray", /, shape: tuple[int, ...]) -> "ManifestArra
)

# do broadcasting of entries in manifest
broadcasted_paths = np.broadcast_to(
x.manifest._paths,
shape=new_chunk_grid_shape,
broadcasted_paths = cast( # `np.broadcast_to` apparently is type hinted as if the output could have Any dtype
np.ndarray[Any, np.dtypes.StringDType],
np.broadcast_to(
x.manifest._paths,
shape=new_chunk_grid_shape,
),
)

broadcasted_offsets = np.broadcast_to(
x.manifest._offsets,
shape=new_chunk_grid_shape,
Expand Down
9 changes: 6 additions & 3 deletions virtualizarr/manifests/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class ChunkManifest:
so it's not possible to have a ChunkManifest object that does not represent a valid grid of chunks.
"""

_paths: np.ndarray[Any, np.dtypes.StringDType] # type: ignore[name-defined]
_paths: np.ndarray[Any, np.dtypes.StringDType]
_offsets: np.ndarray[Any, np.dtype[np.uint64]]
_lengths: np.ndarray[Any, np.dtype[np.uint64]]

Expand Down Expand Up @@ -113,7 +113,10 @@ def __init__(self, entries: dict) -> None:
shape = get_chunk_grid_shape(entries.keys())

# Initializing to empty implies that entries with path='' are treated as missing chunks
paths = np.empty(shape=shape, dtype=np.dtypes.StringDType()) # type: ignore[attr-defined]
paths = cast( # `np.empty` apparently is type hinted as if the output could have Any dtype
np.ndarray[Any, np.dtypes.StringDType],
np.empty(shape=shape, dtype=np.dtypes.StringDType()),
)
offsets = np.empty(shape=shape, dtype=np.dtype("uint64"))
lengths = np.empty(shape=shape, dtype=np.dtype("uint64"))

Expand Down Expand Up @@ -141,7 +144,7 @@ def __init__(self, entries: dict) -> None:
@classmethod
def from_arrays(
cls,
paths: np.ndarray[Any, np.dtype[np.dtypes.StringDType]], # type: ignore[name-defined]
paths: np.ndarray[Any, np.dtypes.StringDType],
offsets: np.ndarray[Any, np.dtype[np.uint64]],
lengths: np.ndarray[Any, np.dtype[np.uint64]],
) -> "ChunkManifest":
Expand Down

0 comments on commit 8d53227

Please sign in to comment.