Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 15 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ jobs:
- name: Run ruff check
run: uv run ruff check

typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install uv
uses: astral-sh/setup-uv@v3
- name: Install dev dependencies
run: uv sync --extra dev
- name: Run mypy
run: uv run mypy

tests:
runs-on: ubuntu-latest
steps:
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ help:
@echo "Targets:"
@echo " help Show this help message"
@echo " lint Run linter and format checker (ruff check + ruff format --check)"
@echo " typecheck Run mypy on the current typed baseline"
@echo " fix Auto-fix lint issues and format code (ruff check --fix + ruff format)"
@echo " lock Update uv.lock lockfile"
@echo " build Install the project with dev and docs dependencies"
Expand All @@ -17,6 +18,10 @@ lint: lock
uv run ruff check
uv run ruff format --check .

.PHONY: typecheck
typecheck: lock
uv run mypy

.PHONY: fix
fix: lock
uv run ruff check --fix --unsafe-fixes
Expand Down Expand Up @@ -45,4 +50,4 @@ clean:

.PHONY: test
test: lock
uv run pytest -vv -s
uv run pytest -vv -s
10 changes: 6 additions & 4 deletions lance_ray/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

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

from typing import TYPE_CHECKING, Optional, Union
from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, Optional, Union, cast

import pyarrow as pa

Expand All @@ -12,13 +13,14 @@


def pd_to_arrow(
df: Union[pa.Table, "pd.DataFrame", dict], schema: Optional[pa.Schema]
df: Union[pa.Table, "pd.DataFrame", Mapping[str, Any]],
schema: Optional[pa.Schema],
) -> pa.Table:
"""Convert a pandas DataFrame to pyarrow Table."""
from lance.dependencies import _PANDAS_AVAILABLE
from lance.dependencies import pandas as pd

if isinstance(df, dict):
if isinstance(df, Mapping):
return pa.Table.from_pydict(df, schema=schema)
elif _PANDAS_AVAILABLE and isinstance(df, pd.DataFrame):
tbl = pa.Table.from_pandas(df, schema=schema)
Expand All @@ -31,4 +33,4 @@ def pd_to_arrow(
return new_table
elif isinstance(df, pa.Table) and df.num_rows > 0 and schema is not None:
return df.cast(schema)
return df
return cast(pa.Table, df)
6 changes: 3 additions & 3 deletions lance_ray/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def validate_uri_or_namespace(
def _get_cached_namespace(
namespace_impl: str,
namespace_properties_tuple: Optional[tuple[tuple[str, str], ...]],
):
) -> Any:
"""Internal cached namespace loader. Use get_or_create_namespace() instead."""
import lance_namespace as ln

Expand All @@ -168,7 +168,7 @@ def _get_cached_namespace(
def get_or_create_namespace(
namespace_impl: Optional[str],
namespace_properties: Optional[dict[str, str]],
):
) -> Any | None:
"""Get or create a cached namespace client.

This function loads a namespace client from cache or creates a new one.
Expand Down Expand Up @@ -197,7 +197,7 @@ def _create_storage_options_provider(
namespace_impl: Optional[str],
namespace_properties: Optional[dict[str, str]],
table_id: Optional[list[str]],
):
) -> Any | None:
"""Create a LanceNamespaceStorageOptionsProvider (pylance 4.x only)."""
if not has_namespace_params(namespace_impl, table_id):
return None
Expand Down
13 changes: 13 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ dependencies = [

[project.optional-dependencies]
dev = [
"mypy>=1.10,<2",
"pandas-stubs",
"pyarrow-stubs",
"pytest-asyncio>=1.0.0",
"pytest-xdist>=3.6.0",
"ruff>=0.8.0",
Expand Down Expand Up @@ -65,6 +68,16 @@ ignore = ["E501", "UP045"]
[tool.ruff.format]
quote-style = "double"

[tool.mypy]
python_version = "3.10"
strict = true
follow_imports = "skip"
files = [
"lance_ray/pandas.py",
"lance_ray/pool.py",
"lance_ray/utils.py",
]


[tool.pytest.ini_options]
testpaths = ["tests"]
Expand Down
Loading
Loading