Skip to content

Commit

Permalink
docs: Add docs for Read, Scan, BaseImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
dangotbanned committed Jan 30, 2025
1 parent cbd04e3 commit c0a92a6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
11 changes: 1 addition & 10 deletions altair/datasets/_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,11 @@ class Reader(Generic[IntoDataFrameT, IntoFrameT]):
Use ``reader(...)`` instead of instantiating ``Reader`` directly.
"""

# TODO: Docs
_read: Sequence[Read[IntoDataFrameT]]
"""Eager file read functions."""

# TODO: Docs
_scan: Sequence[Scan[IntoFrameT]]
"""
*Optionally*-lazy file read/scan functions.
Used exclusively for ``metadata.parquet``.
Currently ``"polars"`` is the only lazy option.
All others defer to the eager variant.
"""
"""Lazy file read functions."""

_name: str
"""
Expand Down
33 changes: 29 additions & 4 deletions altair/datasets/_readimpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@
bound="nwt.NativeFrame | nw.DataFrame[Any] | nw.LazyFrame | nwt.DataFrameLike",
default=nw.LazyFrame,
)
Scan = TypeAliasType("Scan", "BaseImpl[IntoFrameT]", type_params=(IntoFrameT,))
Read = TypeAliasType("Read", "BaseImpl[IntoDataFrameT]", type_params=(IntoDataFrameT,))
"""An *eager* file read function."""

Scan = TypeAliasType("Scan", "BaseImpl[IntoFrameT]", type_params=(IntoFrameT,))
"""A *lazy* file read function."""


class Skip(Enum):
Expand All @@ -73,12 +76,33 @@ def __repr__(self) -> Literal["<Skip>"]:


class BaseImpl(Generic[R]):
"""
A function wrapped with dataset support constraints.
The ``include``, ``exclude`` properties form a `NIMPLY gate`_ (`Material nonimplication`_).
Examples
--------
For some dataset ``D``, we can use ``fn`` if::
impl: BaseImpl
impl.include(D) and not impl.exclude(D)
.. _NIMPLY gate:
https://en.m.wikipedia.org/wiki/NIMPLY_gate
.. _Material nonimplication:
https://en.m.wikipedia.org/wiki/Material_nonimplication#Truth_table
"""

fn: Callable[..., R]
"""Wrapped read function."""
"""Wrapped read/scan function."""

include: MetaIs
"""Passing this makes ``fn`` a candidate."""
"""Constraint indicating ``fn`` **supports** reading a dataset."""

exclude: MetaIs
"""Passing this overrides ``include``, transforming into an error."""
"""Constraint *subsetting* ``include`` to mark **non-support**."""

def __init__(
self,
Expand Down Expand Up @@ -121,6 +145,7 @@ def unwrap_or_skip(

@classmethod
def _exclude_none(cls) -> MetaIs:
"""Represents the empty set."""
return is_meta()

def __setattr__(self, name: str, value: Any):
Expand Down

0 comments on commit c0a92a6

Please sign in to comment.