From ae0a02b75e5201424638159286b835f8e6a93f81 Mon Sep 17 00:00:00 2001 From: "J.P. Dark" <24235303+jp-dark@users.noreply.github.com> Date: Mon, 23 Oct 2023 15:27:48 -0400 Subject: [PATCH] Fix failing tests in older versions of Python --- tiledb/cf/core/_fragment_writer.py | 18 +++++++++--------- tiledb/cf/core/source.py | 3 ++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/tiledb/cf/core/_fragment_writer.py b/tiledb/cf/core/_fragment_writer.py index 73edc39..3b012be 100644 --- a/tiledb/cf/core/_fragment_writer.py +++ b/tiledb/cf/core/_fragment_writer.py @@ -115,7 +115,7 @@ def write(self, array: tiledb.libtiledb.Array, *, skip_metadata: bool = False): if hasattr(attr_data, "fill") and attr_data.fill != attr.fill[0]: attr_data.fill = attr.fill - array[*region] = {name: data.values for name, data in self._attr_data.items()} + array[region] = {name: data.values for name, data in self._attr_data.items()} if not skip_metadata: for name, data in self._attr_data.items(): @@ -152,7 +152,7 @@ def __init__( ) self._size = np.prod(self._shape) - def coordinates(self): + def coordinates(self) -> Tuple[np.ndarray]: def create_coords(dim_range, dtype): if dtype.kind in {"u", "i"}: dt = 1 @@ -188,15 +188,15 @@ def shape(self) -> Optional[Tuple[int, ...]]: def size(self) -> int: return self._size - def subarray(self) -> List[slice, ...]: - return [ + def subarray(self) -> Tuple[slice, ...]: + return tuple( ( slice(dim_range[0], dim_range[1] + 1) if np.issubdtype(type(dim_range[1]), np.integer) else slice(dim_range[0], dim_range[1]) ) for dim_range in self._region - ] + ) def write_metadata(self, array: tiledb.libtiledb.Array): """Write any metadata associated with this region.""" @@ -211,7 +211,7 @@ def __init__(self, dims: Tuple[SharedDim], size: int): # Set the size of the data. self._size = size - def coordinates(self): + def coordinates(self) -> Tuple[np.ndarray]: for idim, data in enumerate(self._dim_data): if data is None: raise ValueError( @@ -247,7 +247,7 @@ def shape(self) -> Optional[Tuple[int, ...]]: def size(self) -> int: return self._size - def subarray(self) -> List[slice, ...]: + def subarray(self) -> Tuple[slice, ...]: raise RuntimeError("Cannot construct a subarray for a sparse region.") def write_metadata(self, array: tiledb.libtiledb.Array): @@ -275,7 +275,7 @@ def __init__(self, dims: Tuple[SharedDim], shape: Tuple[int, ...]): self._shape = shape self._size = np.prod(shape) - def coordinates(self): + def coordinates(self) -> Tuple[np.ndarray]: for idim, data in enumerate(self._dim_data): if data is None: raise ValueError( @@ -315,7 +315,7 @@ def shape(self) -> Optional[Tuple[int, ...]]: def size(self) -> int: return self._size - def subarray(self) -> List[slice, ...]: + def subarray(self) -> Tuple[slice, ...]: raise RuntimeError("Cannot construct a subarray for a sparse region.") def write_metadata(self, array: tiledb.libtiledb.Array): diff --git a/tiledb/cf/core/source.py b/tiledb/cf/core/source.py index 50c0b52..9cb8cc8 100644 --- a/tiledb/cf/core/source.py +++ b/tiledb/cf/core/source.py @@ -1,6 +1,7 @@ -from typing import Any, Mapping, Optional, Protocol, Tuple, Union +from typing import Any, Mapping, Optional, Tuple, Union import numpy as np +from typing_extensions import Protocol class FieldData(Protocol):