-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mypy implementation for adapters in tiled #700
Conversation
Protocols that we should write up together:
|
e317207
to
03b2408
Compare
tiled/adapters/array.py
Outdated
): | ||
metadata: Optional[JSON] = None, | ||
specs: Optional[List[Spec]] = None, | ||
access_policy: Optional[Union[SimpleAccessPolicy, DummyAccessPolicy]] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a good place to use the AccessPolicy
protocol. Same for everywhere else this is used.
tiled/adapters/array.py
Outdated
array = self._array | ||
if slice is not None: | ||
array = array[slice] | ||
array = array[slice] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might as well combine this into a single statement.
tiled/adapters/array.py
Outdated
def read( | ||
self, | ||
slice: Union[ | ||
int, slice, Tuple[Union[int, slice, EllipsisType], ...], EllipsisType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I seems worthwhile to make a "type alias" for this, like you did for JSON
. I suggest the name NDSlice
.
tiled/adapters/array.py
Outdated
def slice_and_shape_from_block_and_chunks(block, chunks): | ||
def slice_and_shape_from_block_and_chunks( | ||
block: Tuple[int, ...], chunks: Tuple[Tuple[int, ...], ...] | ||
) -> Tuple[Tuple[slice, ...], Tuple[int, ...]]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
) -> Tuple[Tuple[slice, ...], Tuple[int, ...]]: | |
) -> Tuple[NDSlice, Tuple[int, ...]]: |
tiled/adapters/awkward.py
Outdated
return self._metadata | ||
|
||
def read_buffers(self, form_keys=None): | ||
def read_buffers(self, form_keys: Optional[List[str]] = None) -> Dict[str, Any]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def read_buffers(self, form_keys: Optional[List[str]] = None) -> Dict[str, Any]: | |
def read_buffers(self, form_keys: Optional[List[str]] = None) -> Dict[str, bytes]: |
if len(self.blocks) > 1: | ||
raise NotImplementedError | ||
uri = self.blocks[(0,) * len(self._structure.shape)] | ||
data.to_parquet(path_from_uri(uri)) | ||
|
||
def read(self, slice=...): | ||
def read(self, slice: Optional[Union[int, slice]]) -> NDArray[Any]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def read(self, slice: Optional[Union[int, slice]]) -> NDArray[Any]: | |
def read(self, slice: Optional[Union[int, slice]]) -> sparse.COO: |
tiled/adapters/tiff.py
Outdated
@@ -22,13 +26,23 @@ class TiffAdapter: | |||
|
|||
def __init__( | |||
self, | |||
data_uri, | |||
data_uri: Union[str, List[str]], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data_uri: Union[str, List[str]], | |
data_uri: str, |
tiled/adapters/zarr.py
Outdated
|
||
INLINED_DEPTH = int(os.getenv("TILED_HDF5_INLINED_CONTENTS_MAX_DEPTH", "7")) | ||
|
||
|
||
def read_zarr(data_uri, structure=None, **kwargs): | ||
def read_zarr( | ||
data_uri: Union[str, List[str]], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data_uri: Union[str, List[str]], | |
data_uri: str, |
tiled/adapters/sparse.py
Outdated
def read_block(self, block, slice=None): | ||
def read_block( | ||
self, block: Tuple[int, ...], slice: Optional[Union[int, slice]] = None | ||
) -> NDArray[Any]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
) -> NDArray[Any]: | |
) -> sparse.COO: |
tiled/adapters/sparse.py
Outdated
coords, data = self.blocks[block] | ||
_, shape = slice_and_shape_from_block_and_chunks(block, self._structure.chunks) | ||
arr = sparse.COO(data=data[:], coords=coords[:], shape=shape) | ||
if slice: | ||
arr = arr[slice] | ||
return arr | ||
|
||
def read(self, slice=None): | ||
def read(self, slice: Optional[Union[int, slice]] = None) -> NDArray[Any]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def read(self, slice: Optional[Union[int, slice]] = None) -> NDArray[Any]: | |
def read(self, slice: Optional[Union[int, slice]] = None) -> sparse.COO: |
15ebb1b
to
3f57d4c
Compare
1d4b7a1
to
453b807
Compare
pass | ||
|
||
|
||
if sys.version_info < (3, 9): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this PR the time to upgrade Tiled's minimum supported python version to SPEC0, which at present would be 3.10 or greater? We could then remove this Mapping stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One or two users out there have asked if we can give them a 3.8 (or even a 3.7) compatible release up through the first beta, so they have at least a basically usable client available in legacy environments.
I figure we'll fast-forward to 3.10 shortly after tagging beta.
beginning of mypy implementation in tiled. It is not ready to merge.