Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b409664
fix(devcontainer): Add stage to Docker build for devcontainer
DiamondJoseph Jul 24, 2025
94d24af
chore(types): Add type hints and hierarchy to Structure types
DiamondJoseph Jul 24, 2025
b7914d4
fix type checking issues on various versions
DiamondJoseph Jul 24, 2025
eb77a11
ClassVar
DiamondJoseph Jul 24, 2025
1833fff
Numpy types
DiamondJoseph Jul 24, 2025
92eb76b
Add root Adapter type
DiamondJoseph Jul 28, 2025
0ee1c44
chore: Type hint and rationalise adapters
DiamondJoseph Jul 29, 2025
c203990
Merge branch 'devcontainer' into typed_adapters
dan-fernandes Jul 30, 2025
d156559
Changes to fix pre-commit
dan-fernandes Jul 31, 2025
9d34c51
Fixes for pre-commit including correct typing of MapAdapter
dan-fernandes Jul 31, 2025
987be06
Fixes for pre-commit
dan-fernandes Aug 5, 2025
d5bf1b4
Adopt Zarr expectations of JSON type
DiamondJoseph Aug 5, 2025
e007337
Extract Zarr Adapter from array assumptions
DiamondJoseph Aug 5, 2025
f3df553
Fixes for pre-commit
dan-fernandes Aug 5, 2025
0a8ff1c
Retype xarray adapters, MadAdapter
dan-fernandes Aug 6, 2025
04bb74f
Add types-cachetools to dev requirements
dan-fernandes Aug 6, 2025
ac69d59
Fixes to pass pre-commit
dan-fernandes Aug 12, 2025
044868a
Remove type vars from non generic classes
dan-fernandes Aug 12, 2025
a2c6b0d
Add SQLAdapter.structure_family
dan-fernandes Aug 12, 2025
2d64f16
Fix treating .structure_family as a property
dan-fernandes Aug 13, 2025
e11c8ba
Make ParquetDatabaseAdapter inherit from Adapter[TableStructure]
dan-fernandes Aug 13, 2025
60d4f79
Fixes for pre-commit
dan-fernandes Aug 13, 2025
1665e61
Make structure_family an attribute, make metadata a callable
dan-fernandes Aug 13, 2025
c755afa
Make CSVAdapter inherit directly from Adapter[TableStructure]
dan-fernandes Aug 13, 2025
7bea172
Fix structure family pickling issue
dan-fernandes Aug 19, 2025
dd234f2
Fix hdf5 adapter self referential metadata
dan-fernandes Aug 19, 2025
a75bc4b
Change ZarrGroupAdapter conatiner structure to use list of keys
dan-fernandes Aug 19, 2025
ce60c36
Change NPYAdapter to inherit directly from Adapter[ArrayStructure]
dan-fernandes Aug 19, 2025
c640b40
Remove unused print statement
dan-fernandes Aug 19, 2025
03115cb
Remove AnyStructure
dan-fernandes Aug 19, 2025
eab26a2
Merge from main
dan-fernandes Aug 20, 2025
3c7bd2b
Fix typing for backwards compatibility
dan-fernandes Aug 20, 2025
7fe1185
Fix metadata argument
dan-fernandes Aug 20, 2025
a8002b6
Add type to ExceAdapter(MadAdapter) generic
dan-fernandes Aug 20, 2025
7dcf060
Add return type, remove unused type ignore
dan-fernandes Aug 20, 2025
cdd0d84
Fix JPEGAdapter.read_block signature, remove unused type ignore
dan-fernandes Aug 20, 2025
a32dd05
Merge 'main' into tiled_adapters
dan-fernandes Aug 29, 2025
0ec4b3e
Merge branch 'main' into typed_adapters
danielballan Oct 7, 2025
73eb631
Fix merge conflict resolution
danielballan Oct 7, 2025
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
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ repos:
hooks:
- id: mypy
args: [--strict]
additional_dependencies: [types-cachetools]
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ dev = [
"sphinx-copybutton",
"sphinx_rtd_theme",
"sphinxcontrib-mermaid",
"types-cachetools",
]
# These are used by the server to read files in the respective formats.
formats = [
Expand Down
71 changes: 5 additions & 66 deletions tiled/adapters/array.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import contextlib
from typing import Any, List, Optional, Set, Tuple
from typing import Any, List, Optional, Tuple

import dask.array
import numpy
import pandas
from numpy.typing import NDArray

from tiled.adapters.core import Adapter

from ..ndslice import NDSlice
from ..storage import Storage
from ..structures.array import ArrayStructure
from ..structures.core import Spec, StructureFamily
from ..type_aliases import JSON


class ArrayAdapter:
class ArrayAdapter(Adapter[ArrayStructure]):
"""
Wrap an array-like object in an interface that Tiled can serve.

Expand All @@ -29,7 +30,6 @@ class ArrayAdapter:
"""

structure_family = StructureFamily.array
supported_storage: Set[type[Storage]] = set()

def __init__(
self,
Expand All @@ -39,19 +39,8 @@ def __init__(
metadata: Optional[JSON] = None,
specs: Optional[List[Spec]] = None,
) -> None:
"""

Parameters
----------
array :
structure :
metadata :
specs :
"""
self._array = array
self._structure = structure
self._metadata = metadata or {}
self.specs = specs or []
super().__init__(structure, metadata=metadata, specs=specs)

@classmethod
def from_array(
Expand All @@ -64,21 +53,6 @@ def from_array(
metadata: Optional[JSON] = None,
specs: Optional[List[Spec]] = None,
) -> "ArrayAdapter":
"""

Parameters
----------
array :
shape :
chunks :
dims :
metadata :
specs :

Returns
-------

"""
# May be a list of something; convert to array
if not hasattr(array, "__array__"):
array = numpy.asanyarray(array)
Expand Down Expand Up @@ -118,26 +92,10 @@ def __repr__(self) -> str:
def dims(self) -> Optional[Tuple[str, ...]]:
return self._structure.dims

def metadata(self) -> JSON:
return self._metadata

def structure(self) -> ArrayStructure:
return self._structure

def read(
self,
slice: NDSlice = NDSlice(...),
) -> NDArray[Any]:
"""

Parameters
----------
slice :

Returns
-------

"""
# _array[...] requires an actual tuple, not just a subclass of tuple
array = self._array[tuple(slice)] if slice else self._array
if isinstance(self._array, dask.array.Array):
Expand All @@ -149,17 +107,6 @@ def read_block(
block: Tuple[int, ...],
slice: NDSlice = NDSlice(...),
) -> NDArray[Any]:
"""

Parameters
----------
block :
slice :

Returns
-------

"""
# Slice the whole array to get this block.
slice_, _ = slice_and_shape_from_block_and_chunks(block, self._structure.chunks)
# _array[...] requires an actual tuple, not just a subclass of tuple
Expand All @@ -176,14 +123,6 @@ def slice_and_shape_from_block_and_chunks(
) -> tuple[NDSlice, NDSlice]:
"""
Given dask-like chunks and block id, return slice and shape of the block.
Parameters
----------
block :
chunks :

Returns
-------

"""
slice_ = []
shape = []
Expand Down
37 changes: 13 additions & 24 deletions tiled/adapters/arrow.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import copy
from collections.abc import Set
from pathlib import Path
from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Union
from urllib.parse import quote_plus

import pandas
import pyarrow
import pyarrow.feather as feather
import pyarrow.fs

from tiled.adapters.core import Adapter

from ..catalog.orm import Node
from ..storage import FileStorage, Storage
Expand All @@ -19,37 +21,29 @@
from .utils import init_adapter_from_catalog


class ArrowAdapter:
class ArrowAdapter(Adapter[TableStructure]):
"""ArrowAdapter Class"""

structure_family = StructureFamily.table
supported_storage = {FileStorage}
structure_family: StructureFamily = StructureFamily.table

def __init__(
self,
data_uris: List[str],
structure: Optional[TableStructure] = None,
*,
metadata: Optional[JSON] = None,
specs: Optional[List[Spec]] = None,
**kwargs: Optional[Any],
) -> None:
"""

Parameters
----------
data_uris : list of uris where data sits.
structure :
metadata :
specs :
"""
# TODO Store data_uris instead and generalize to non-file schemes.
self._partition_paths = [path_from_uri(uri) for uri in data_uris]
self._metadata = metadata or {}
if structure is None:
table = feather.read_table(self._partition_paths)
structure = TableStructure.from_arrow_table(table)
self._structure = structure
self.specs = list(specs or [])
super().__init__(structure, metadata=metadata, specs=specs)

@classmethod
def supported_storage(cls) -> Set[type[Storage]]:
return {FileStorage}

@classmethod
def from_catalog(
Expand All @@ -59,10 +53,7 @@ def from_catalog(
/,
**kwargs: Optional[Any],
) -> "ArrowAdapter":
return init_adapter_from_catalog(cls, data_source, node, **kwargs) # type: ignore

def metadata(self) -> JSON:
return self._metadata
return init_adapter_from_catalog(cls, data_source, node, **kwargs)

@classmethod
def init_storage(
Expand Down Expand Up @@ -101,9 +92,6 @@ def init_storage(
data_source.assets.extend(assets)
return data_source

def structure(self) -> TableStructure:
return self._structure

def get(self, key: str) -> Union[ArrayAdapter, None]:
if key not in self.structure().columns:
return None
Expand Down Expand Up @@ -153,6 +141,7 @@ def from_single_file(
cls,
data_uri: str,
structure: Optional[TableStructure] = None,
*,
metadata: Optional[JSON] = None,
specs: Optional[List[Spec]] = None,
) -> "ArrowAdapter":
Expand Down
26 changes: 7 additions & 19 deletions tiled/adapters/awkward.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@
import awkward.forms
from numpy.typing import NDArray

from ..storage import FileStorage
from tiled.adapters.core import Adapter

from ..structures.awkward import AwkwardStructure
from ..structures.core import Spec, StructureFamily
from ..type_aliases import JSON
from .awkward_directory_container import DirectoryContainer


class AwkwardAdapter:
structure_family = StructureFamily.awkward
supported_storage = {FileStorage}
class AwkwardAdapter(Adapter[AwkwardStructure]):
structure_family: StructureFamily = StructureFamily.awkward

def __init__(
self,
container: DirectoryContainer,
structure: AwkwardStructure,
*,
metadata: Optional[JSON] = None,
specs: Optional[List[Spec]] = None,
) -> None:
Expand All @@ -32,14 +33,13 @@ def __init__(
specs :
"""
self.container = container
self._metadata = metadata or {}
self._structure = structure
self.specs = list(specs or [])
super().__init__(structure, metadata=metadata, specs=specs)

@classmethod
def from_array(
cls,
array: NDArray[Any],
*,
metadata: Optional[JSON] = None,
specs: Optional[List[Spec]] = None,
) -> "AwkwardAdapter":
Expand All @@ -64,15 +64,6 @@ def from_array(
specs=specs,
)

def metadata(self) -> JSON:
"""

Returns
-------

"""
return self._metadata

def read_buffers(self, form_keys: Optional[List[str]] = None) -> Dict[str, bytes]:
"""

Expand Down Expand Up @@ -118,6 +109,3 @@ def write(self, container: DirectoryContainer) -> None:
"""
for form_key, value in container.items():
self.container[form_key] = value

def structure(self) -> AwkwardStructure:
return self._structure
13 changes: 8 additions & 5 deletions tiled/adapters/awkward_buffers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import copy
from collections.abc import Set
from pathlib import Path
from typing import Any, List, Optional
from urllib.parse import quote_plus
Expand All @@ -12,7 +13,7 @@
from ..catalog.orm import Node
from ..storage import FileStorage, Storage
from ..structures.awkward import AwkwardStructure
from ..structures.core import Spec, StructureFamily
from ..structures.core import Spec
from ..structures.data_source import Asset, DataSource
from ..type_aliases import JSON
from ..utils import path_from_uri
Expand All @@ -22,9 +23,6 @@


class AwkwardBuffersAdapter(AwkwardAdapter):
structure_family = StructureFamily.awkward
supported_storage = {FileStorage}

@classmethod
def init_storage(
cls,
Expand Down Expand Up @@ -58,6 +56,7 @@ def __init__(
self,
data_uri: str,
structure: AwkwardStructure,
*,
metadata: Optional[JSON] = None,
specs: Optional[List[Spec]] = None,
):
Expand All @@ -73,6 +72,10 @@ def __init__(
specs=specs,
)

@classmethod
def supported_storage(cls) -> Set[type[Storage]]:
return {FileStorage}

@classmethod
def from_catalog(
cls,
Expand All @@ -81,4 +84,4 @@ def from_catalog(
/,
**kwargs: Optional[Any],
) -> "AwkwardBuffersAdapter":
return init_adapter_from_catalog(cls, data_source, node, **kwargs) # type: ignore
return init_adapter_from_catalog(cls, data_source, node, **kwargs)
10 changes: 10 additions & 0 deletions tiled/adapters/container.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from collections.abc import Mapping
from typing import Generic

from tiled.adapters.core import A, Adapter
from tiled.structures.container import ContainerStructure
from tiled.structures.core import StructureFamily


class ContainerAdapter(Adapter[ContainerStructure], Mapping[str, A], Generic[A]):
structure_family: StructureFamily = StructureFamily.container
Loading