Skip to content

Commit 798becb

Browse files
committed
chore: add mypy typecheck baseline
1 parent 90b9128 commit 798becb

6 files changed

Lines changed: 221 additions & 11 deletions

File tree

.github/workflows/pr.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ jobs:
3939
- name: Run ruff check
4040
run: uv run ruff check
4141

42+
typecheck:
43+
runs-on: ubuntu-latest
44+
steps:
45+
- uses: actions/checkout@v4
46+
- name: Set up Python
47+
uses: actions/setup-python@v4
48+
with:
49+
python-version: '3.10'
50+
- name: Install uv
51+
uses: astral-sh/setup-uv@v3
52+
- name: Install dev dependencies
53+
run: uv sync --extra dev
54+
- name: Run mypy
55+
run: uv run mypy
56+
4257
tests:
4358
runs-on: ubuntu-latest
4459
steps:

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ help:
55
@echo "Targets:"
66
@echo " help Show this help message"
77
@echo " lint Run linter and format checker (ruff check + ruff format --check)"
8+
@echo " typecheck Run mypy on the current typed baseline"
89
@echo " fix Auto-fix lint issues and format code (ruff check --fix + ruff format)"
910
@echo " lock Update uv.lock lockfile"
1011
@echo " build Install the project with dev and docs dependencies"
@@ -17,6 +18,10 @@ lint: lock
1718
uv run ruff check
1819
uv run ruff format --check .
1920

21+
.PHONY: typecheck
22+
typecheck: lock
23+
uv run mypy
24+
2025
.PHONY: fix
2126
fix: lock
2227
uv run ruff check --fix --unsafe-fixes
@@ -45,4 +50,4 @@ clean:
4550

4651
.PHONY: test
4752
test: lock
48-
uv run pytest -vv -s
53+
uv run pytest -vv -s

lance_ray/pandas.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
"""Utility functions for lance-ray."""
55

6-
from typing import TYPE_CHECKING, Optional, Union
6+
from collections.abc import Mapping
7+
from typing import TYPE_CHECKING, Any, Optional, Union, cast
78

89
import pyarrow as pa
910

@@ -12,13 +13,14 @@
1213

1314

1415
def pd_to_arrow(
15-
df: Union[pa.Table, "pd.DataFrame", dict], schema: Optional[pa.Schema]
16+
df: Union[pa.Table, "pd.DataFrame", Mapping[str, Any]],
17+
schema: Optional[pa.Schema],
1618
) -> pa.Table:
1719
"""Convert a pandas DataFrame to pyarrow Table."""
1820
from lance.dependencies import _PANDAS_AVAILABLE
1921
from lance.dependencies import pandas as pd
2022

21-
if isinstance(df, dict):
23+
if isinstance(df, Mapping):
2224
return pa.Table.from_pydict(df, schema=schema)
2325
elif _PANDAS_AVAILABLE and isinstance(df, pd.DataFrame):
2426
tbl = pa.Table.from_pandas(df, schema=schema)
@@ -31,4 +33,4 @@ def pd_to_arrow(
3133
return new_table
3234
elif isinstance(df, pa.Table) and df.num_rows > 0 and schema is not None:
3335
return df.cast(schema)
34-
return df
36+
return cast(pa.Table, df)

lance_ray/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def validate_uri_or_namespace(
155155
def _get_cached_namespace(
156156
namespace_impl: str,
157157
namespace_properties_tuple: Optional[tuple[tuple[str, str], ...]],
158-
):
158+
) -> Any:
159159
"""Internal cached namespace loader. Use get_or_create_namespace() instead."""
160160
import lance_namespace as ln
161161

@@ -168,7 +168,7 @@ def _get_cached_namespace(
168168
def get_or_create_namespace(
169169
namespace_impl: Optional[str],
170170
namespace_properties: Optional[dict[str, str]],
171-
):
171+
) -> Any | None:
172172
"""Get or create a cached namespace client.
173173
174174
This function loads a namespace client from cache or creates a new one.
@@ -197,7 +197,7 @@ def _create_storage_options_provider(
197197
namespace_impl: Optional[str],
198198
namespace_properties: Optional[dict[str, str]],
199199
table_id: Optional[list[str]],
200-
):
200+
) -> Any | None:
201201
"""Create a LanceNamespaceStorageOptionsProvider (pylance 4.x only)."""
202202
if not has_namespace_params(namespace_impl, table_id):
203203
return None

pyproject.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ dependencies = [
3535

3636
[project.optional-dependencies]
3737
dev = [
38+
"mypy>=1.10,<2",
39+
"pandas-stubs",
40+
"pathspec>=1.1.1",
41+
"pyarrow-stubs",
3842
"pytest-asyncio>=1.0.0",
3943
"pytest-xdist>=3.6.0",
4044
"ruff>=0.8.0",
@@ -65,6 +69,16 @@ ignore = ["E501", "UP045"]
6569
[tool.ruff.format]
6670
quote-style = "double"
6771

72+
[tool.mypy]
73+
python_version = "3.10"
74+
strict = true
75+
follow_imports = "skip"
76+
files = [
77+
"lance_ray/pandas.py",
78+
"lance_ray/pool.py",
79+
"lance_ray/utils.py",
80+
]
81+
6882

6983
[tool.pytest.ini_options]
7084
testpaths = ["tests"]

0 commit comments

Comments
 (0)