Skip to content

Commit

Permalink
misc type-check fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-williams committed Nov 19, 2024
1 parent d9ae962 commit e5ea722
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 15 deletions.
6 changes: 4 additions & 2 deletions apis/python/src/tiledbsoma/_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
from ._soma_array import SOMAArray
from ._tdb_handles import DataFrameWrapper
from ._types import (
NPFInfo,
NPFloating,
NPIInfo,
NPInteger,
OpenTimestamp,
StatusAndReason,
Expand Down Expand Up @@ -925,7 +927,7 @@ def _fill_out_slot_soma_domain(
if is_max_domain:
# Core max domain is immutable. If unspecified, it should be as big
# as possible since it can never be resized.
iinfo = np.iinfo(cast(NPInteger, dtype))
iinfo: NPIInfo = np.iinfo(cast(NPInteger, dtype))
slot_domain = iinfo.min, iinfo.max - 1
# Here the slot_domain isn't specified by the user; we're setting it.
# The SOMA spec disallows negative soma_joinid.
Expand All @@ -943,7 +945,7 @@ def _fill_out_slot_soma_domain(
slot_domain = 0, 0
elif np.issubdtype(dtype, NPFloating):
if is_max_domain:
finfo = np.finfo(cast(NPFloating, dtype))
finfo: NPFInfo = np.finfo(cast(NPFloating, dtype))
slot_domain = finfo.min, finfo.max
saturated_range = True
else:
Expand Down
10 changes: 5 additions & 5 deletions apis/python/src/tiledbsoma/_fast_csr.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def append(
)
row_ind = rows_future.result()
col_ind = cols_future.result()
self.coo_chunks.append((row_ind, col_ind, data.to_numpy())) # type: ignore[arg-type]
self.coo_chunks.append((row_ind, col_ind, data.to_numpy()))
_accum_row_length(self.row_length, row_ind)

def finalize(self) -> AccumulatedCSR:
Expand Down Expand Up @@ -214,7 +214,7 @@ def finalize(self) -> AccumulatedCSR:


@typeguard_ignore # type: ignore[misc]
@numba.jit(nopython=True, nogil=True) # type: ignore[attr-defined,misc]
@numba.jit(nopython=True, nogil=True) # type: ignore[misc]
def _accum_row_length(
row_length: npt.NDArray[np.int64], row_ind: npt.NDArray[np.int64]
) -> None:
Expand All @@ -223,7 +223,7 @@ def _accum_row_length(


@typeguard_ignore # type: ignore[misc]
@numba.jit(nopython=True, nogil=True) # type: ignore[attr-defined,misc]
@numba.jit(nopython=True, nogil=True) # type: ignore[misc]
def _copy_chunk_range(
row_ind_chunk: npt.NDArray[np.signedinteger[npt.NBitBase]],
col_ind_chunk: npt.NDArray[np.signedinteger[npt.NBitBase]],
Expand All @@ -245,7 +245,7 @@ def _copy_chunk_range(


@typeguard_ignore # type: ignore[misc]
@numba.jit(nopython=True, nogil=True) # type: ignore[attr-defined,misc]
@numba.jit(nopython=True, nogil=True) # type: ignore[misc]
def _copy_chunklist_range(
chunk_list: numba.typed.List,
data: NPNDArray,
Expand All @@ -271,7 +271,7 @@ def _copy_chunklist_range(


@typeguard_ignore # type: ignore[misc]
@numba.jit(nopython=True, nogil=True) # type: ignore[attr-defined,misc]
@numba.jit(nopython=True, nogil=True) # type: ignore[misc]
def _finalize_indptr(indptr: npt.NDArray[np.signedinteger[npt.NBitBase]]) -> None:
prev = 0
for r in range(len(indptr)):
Expand Down
2 changes: 1 addition & 1 deletion apis/python/src/tiledbsoma/_fastercsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def to_scipy(
indptr = (self.indptr[idx_start : idx_end + 1]).copy()
indices = self.indices[indptr[0] : indptr[-1]].copy()
data = self.data[indptr[0] : indptr[-1]].copy()
indptr -= indptr[0] # type: ignore[misc]
indptr -= indptr[0]

shape = (
(n_major, self.shape[1])
Expand Down
2 changes: 1 addition & 1 deletion apis/python/src/tiledbsoma/_indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_indexer(self, target: IndexerDataType) -> npt.NDArray[np.intp]:
Args:
target: Data to return re-index data for.
"""
return ( # type: ignore[no-any-return]
return (
self._reindexer.get_indexer_pyarrow(target)
if isinstance(target, (pa.Array, pa.ChunkedArray))
else self._reindexer.get_indexer_general(target)
Expand Down
2 changes: 1 addition & 1 deletion apis/python/src/tiledbsoma/_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def by_var(self, coords: Numpyable) -> npt.NDArray[np.intp]:
def _to_numpy(it: Numpyable) -> npt.NDArray[np.int64]:
if isinstance(it, np.ndarray):
return it
return it.to_numpy() # type: ignore[no-any-return]
return it.to_numpy()


@attrs.define(frozen=True)
Expand Down
4 changes: 4 additions & 0 deletions apis/python/src/tiledbsoma/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
NPFloating = np.floating[npt.NBitBase]
NPNDArray = npt.NDArray[np.number[npt.NBitBase]]
NPIntArray = npt.NDArray[np.integer[npt.NBitBase]]
NPIInfo = np.iinfo[NPInteger]
NPFInfo = np.finfo[NPFloating]
else:
# When not-type-checking, but running with `pandas>=2`, the "missing" type-params don't affect anything.
PDSeries = pd.Series
Expand All @@ -40,6 +42,8 @@
NPFloating = np.floating
NPNDArray = np.ndarray
NPIntArray = np.ndarray
NPIInfo = np.iinfo
NPFInfo = np.finfo


Path = Union[str, pathlib.Path]
Expand Down
4 changes: 2 additions & 2 deletions apis/python/src/tiledbsoma/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,12 +533,12 @@ def _set_coord(dim_idx: int, sarr: clib.SOMAArray, coord: object) -> None:
ts_dom = pa.array(dom, type=dim.type).cast(pa.int64())

if coord.start is not None:
istart = coord.start.astype("int64")
istart = int(coord.start.astype("int64"))
else:
istart = ts_dom[0].as_py()

if coord.stop is not None:
istop = coord.stop.astype("int64")
istop = int(coord.stop.astype("int64"))
else:
istop = ts_dom[1].as_py()

Expand Down
2 changes: 1 addition & 1 deletion apis/python/src/tiledbsoma/experimental/_xarray_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def update_slice_index(index: slice, dim_size: int) -> slice:

# Read the data from SOMA, convert to numpy, and reshape.
result = self._array.read(key).to_numpy()
return result.reshape(output_shape) # type: ignore
return result.reshape(output_shape)

@property
def ndim(self) -> int:
Expand Down
4 changes: 2 additions & 2 deletions apis/python/src/tiledbsoma/experimental/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,11 +729,11 @@ def _write_visium_spots(
if additional_metadata is None:
additional_metadata = {
"soma_geometry_type": "radius",
"soma_geometry": 0.5 * np.double(spot_diameter), # type: ignore
"soma_geometry": 0.5 * np.double(spot_diameter),
}
else:
additional_metadata["soma_geometry_type"] = "radius"
additional_metadata["soma_geometry"] = 0.5 * np.double(spot_diameter) # type: ignore
additional_metadata["soma_geometry"] = 0.5 * np.double(spot_diameter)
if ingestion_params.write_schema_no_data:
add_metadata(soma_point_cloud, additional_metadata)
return soma_point_cloud
Expand Down

0 comments on commit e5ea722

Please sign in to comment.