Skip to content

Commit

Permalink
docs: Adds module-level doc to altair.datasets
Browse files Browse the repository at this point in the history
- Multiple **brief** examples, for a taste of the public API
  - See (#3763)
- Refs to everywhere a first-time user may need help from
- Also aligned the (`Loader`|`load`) docs w/ eachother and the new phrasing here
  • Loading branch information
dangotbanned committed Jan 22, 2025
1 parent 0c72435 commit 8e4c168
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
65 changes: 64 additions & 1 deletion altair/datasets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,64 @@
"""
Load example datasets **remotely** from `vega-datasets`_.
Provides over **70+** datasets, used throughout our `Example Gallery`_.
You can learn more about each dataset at `datapackage.md`_.
Examples
--------
Load a dataset as a ``DataFrame``/``Table``::
from altair.datasets import load
load("cars")
.. note::
Requires installation of either `polars`_, `pandas`_, or `pyarrow`_.
Get the remote address of a dataset and use directly in a :class:`altair.Chart`::
import altair as alt
from altair.datasets import url
source = url("co2-concentration")
alt.Chart(source).mark_line(tooltip=True).encode(x="Date:T", y="CO2:Q")
.. note::
Works without any additional dependencies.
For greater control over the backend library use::
from altair.datasets import Loader
load = Loader.from_backend("polars")
load("penguins")
load.url("penguins")
This method also provides *precise* <kbd>Tab</kbd> completions on the returned object::
load("cars").<Tab>
# bottom_k
# drop
# drop_in_place
# drop_nans
# dtypes
# ...
.. _vega-datasets:
https://github.com/vega/vega-datasets
.. _Example Gallery:
https://altair-viz.github.io/gallery/index.html#example-gallery
.. _datapackage.md:
https://github.com/vega/vega-datasets/blob/main/datapackage.md
.. _polars:
https://docs.pola.rs/user-guide/installation/
.. _pandas:
https://pandas.pydata.org/docs/getting_started/install.html
.. _pyarrow:
https://arrow.apache.org/docs/python/install.html
"""

from __future__ import annotations

from typing import TYPE_CHECKING
Expand All @@ -22,7 +83,9 @@

load: _Load[Any, Any]
"""
For full IDE completions, instead use:
Get a remote dataset and load as tabular data.
For full <kbd>Tab</kbd> completions, instead use:
from altair.datasets import Loader
load = Loader.from_backend("polars")
Expand Down
2 changes: 1 addition & 1 deletion altair/datasets/_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

class Loader(Generic[IntoDataFrameT, IntoFrameT]):
"""
Load examples **remotely** from `vega-datasets`_, with caching.
Load example datasets **remotely** from `vega-datasets`_, with caching.
A new ``Loader`` must be initialized by specifying a backend:
Expand Down

0 comments on commit 8e4c168

Please sign in to comment.