Skip to content

Commit c3c2eda

Browse files
committed
docs: Make sphinx happy with docs
These changes are very minor in VSCode, but fix a lot of rendering issues on the website
1 parent 106f8bb commit c3c2eda

File tree

5 files changed

+92
-65
lines changed

5 files changed

+92
-65
lines changed

altair/datasets/__init__.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Load example datasets **remotely** from `vega-datasets`_.
2+
Load example datasets *remotely* from `vega-datasets`_.
33
44
Provides over **70+** datasets, used throughout our `Example Gallery`_.
55
@@ -85,24 +85,18 @@
8585
"""
8686
Get a remote dataset and load as tabular data.
8787
88-
For full <kbd>Tab</kbd> completions, instead use:
88+
For full <kbd>Tab</kbd> completions, instead use::
8989
9090
from altair.datasets import Loader
9191
load = Loader.from_backend("polars")
9292
cars = load("cars")
9393
movies = load("movies")
9494
95-
Alternatively, specify ``backend`` during a call:
95+
Alternatively, specify ``backend`` during a call::
9696
9797
from altair.datasets import load
9898
cars = load("cars", backend="polars")
9999
movies = load("movies", backend="polars")
100-
101-
Related
102-
-------
103-
- https://github.com/vega/altair/pull/3631#issuecomment-2480832609
104-
- https://github.com/vega/altair/pull/3631#discussion_r1847111064
105-
- https://github.com/vega/altair/pull/3631#discussion_r1847176465
106100
"""
107101

108102

@@ -124,17 +118,14 @@ def url(
124118
.. note::
125119
Only needed if ``name`` is available in multiple formats.
126120
121+
Returns
122+
-------
123+
``str``
124+
127125
.. _Path.stem:
128126
https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.stem
129127
.. _Path.suffix:
130128
https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.suffix
131-
132-
Related
133-
-------
134-
- https://github.com/vega/altair/pull/3631#issuecomment-2484826592
135-
- https://github.com/vega/altair/pull/3631#issuecomment-2480832711
136-
- https://github.com/vega/altair/discussions/3150#discussioncomment-11280516
137-
- https://github.com/vega/altair/pull/3631#discussion_r1846662053
138129
"""
139130
from altair.datasets._exceptions import AltairDatasetsError
140131

altair/datasets/_cache.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -317,26 +317,27 @@ def path(self) -> Path:
317317
"""
318318
Returns path to datasets cache.
319319
320-
Defaults to (`XDG_CACHE_HOME`_):
320+
Defaults to (`XDG_CACHE_HOME`_)::
321321
322322
"$XDG_CACHE_HOME/altair/"
323323
324-
But can be configured using the environment variable:
324+
But can be configured using the environment variable::
325325
326326
"$ALTAIR_DATASETS_DIR"
327327
328-
You can set this for the current session via:
328+
You can set this for the current session via::
329329
330-
>>> from pathlib import Path
331-
>>> from altair.datasets import load
332-
>>> load.cache.path = Path.home() / ".altair_cache"
330+
from pathlib import Path
331+
from altair.datasets import load
333332
334-
>>> load.cache.path.relative_to(Path.home()).as_posix()
335-
'.altair_cache'
333+
load.cache.path = Path.home() / ".altair_cache"
336334
337-
You can *later* disable caching via:
335+
load.cache.path.relative_to(Path.home()).as_posix()
336+
".altair_cache"
338337
339-
>>> load.cache.path = None
338+
You can *later* disable caching via::
339+
340+
load.cache.path = None
340341
341342
.. _XDG_CACHE_HOME:
342343
https://specifications.freedesktop.org/basedir-spec/latest/#variables

altair/datasets/_loader.py

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929

3030
class Loader(Generic[IntoDataFrameT, IntoFrameT]):
3131
"""
32-
Load example datasets **remotely** from `vega-datasets`_, with caching.
32+
Load example datasets *remotely* from `vega-datasets`_, with caching.
3333
34-
A new ``Loader`` must be initialized by specifying a backend:
34+
A new ``Loader`` must be initialized by specifying a backend::
3535
3636
from altair.datasets import Loader
3737
3838
load = Loader.from_backend("polars")
39-
>>> load # doctest: +SKIP
39+
load
4040
Loader[polars]
4141
4242
.. _vega-datasets:
@@ -81,42 +81,35 @@ def from_backend(cls, backend_name: _Backend = "polars", /) -> Loader[Any, Any]:
8181
.. warning::
8282
Most datasets use a `JSON format not supported`_ by ``pyarrow``
8383
84-
.. _polars defaults:
85-
https://docs.pola.rs/api/python/stable/reference/io.html
86-
.. _pandas defaults:
87-
https://pandas.pydata.org/docs/reference/io.html
88-
.. _JSON format not supported:
89-
https://arrow.apache.org/docs/python/json.html#reading-json-files
90-
9184
Examples
9285
--------
93-
Using ``polars``:
86+
Using ``polars``::
9487
9588
from altair.datasets import Loader
9689
9790
load = Loader.from_backend("polars")
9891
cars = load("cars")
9992
100-
>>> type(cars) # doctest: +SKIP
93+
type(cars)
10194
polars.dataframe.frame.DataFrame
10295
103-
Using ``pandas``:
96+
Using ``pandas``::
10497
10598
load = Loader.from_backend("pandas")
10699
cars = load("cars")
107100
108-
>>> type(cars) # doctest: +SKIP
101+
type(cars)
109102
pandas.core.frame.DataFrame
110103
111-
Using ``pandas``, backed by ``pyarrow`` dtypes:
104+
Using ``pandas``, backed by ``pyarrow`` dtypes::
112105
113106
load = Loader.from_backend("pandas[pyarrow]")
114107
cars = load("cars")
115108
116-
>>> type(cars) # doctest: +SKIP
109+
type(cars)
117110
pandas.core.frame.DataFrame
118111
119-
>>> cars.dtypes # doctest: +SKIP
112+
cars.dtypes
120113
Name string[pyarrow]
121114
Miles_per_Gallon double[pyarrow]
122115
Cylinders int64[pyarrow]
@@ -127,6 +120,13 @@ def from_backend(cls, backend_name: _Backend = "polars", /) -> Loader[Any, Any]:
127120
Year timestamp[ns][pyarrow]
128121
Origin string[pyarrow]
129122
dtype: object
123+
124+
.. _polars defaults:
125+
https://docs.pola.rs/api/python/stable/reference/io.html
126+
.. _pandas defaults:
127+
https://pandas.pydata.org/docs/reference/io.html
128+
.. _JSON format not supported:
129+
https://arrow.apache.org/docs/python/json.html#reading-json-files
130130
"""
131131
obj = Loader.__new__(Loader)
132132
obj._reader = backend(backend_name)
@@ -154,24 +154,19 @@ def __call__(
154154
**kwds
155155
Arguments passed to the underlying read function.
156156
157-
.. _Path.stem:
158-
https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.stem
159-
.. _Path.suffix:
160-
https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.suffix
161-
162157
Examples
163158
--------
164-
Using ``polars``:
159+
Using ``polars``::
165160
166161
from altair.datasets import Loader
167162
168163
load = Loader.from_backend("polars")
169164
source = load("iowa-electricity")
170165
171-
>>> source.columns # doctest: +SKIP
166+
source.columns
172167
['year', 'source', 'net_generation']
173168
174-
>>> source # doctest: +SKIP
169+
source
175170
shape: (51, 3)
176171
┌────────────┬──────────────┬────────────────┐
177172
│ year ┆ source ┆ net_generation │
@@ -191,15 +186,15 @@ def __call__(
191186
│ 2017-01-01 ┆ Renewables ┆ 21933 │
192187
└────────────┴──────────────┴────────────────┘
193188
194-
Using ``pandas``:
189+
Using ``pandas``::
195190
196191
load = Loader.from_backend("pandas")
197192
source = load("iowa-electricity")
198193
199-
>>> source.columns # doctest: +SKIP
194+
source.columns
200195
Index(['year', 'source', 'net_generation'], dtype='object')
201196
202-
>>> source # doctest: +SKIP
197+
source
203198
year source net_generation
204199
0 2001-01-01 Fossil Fuels 35361
205200
1 2002-01-01 Fossil Fuels 35991
@@ -215,15 +210,15 @@ def __call__(
215210
216211
[51 rows x 3 columns]
217212
218-
Using ``pyarrow``:
213+
Using ``pyarrow``::
219214
220215
load = Loader.from_backend("pyarrow")
221216
source = load("iowa-electricity")
222217
223-
>>> source.column_names # doctest: +SKIP
218+
source.column_names
224219
['year', 'source', 'net_generation']
225220
226-
>>> source # doctest: +SKIP
221+
source
227222
pyarrow.Table
228223
year: date32[day]
229224
source: string
@@ -232,6 +227,11 @@ def __call__(
232227
year: [[2001-01-01,2002-01-01,2003-01-01,2004-01-01,2005-01-01,...,2013-01-01,2014-01-01,2015-01-01,2016-01-01,2017-01-01]]
233228
source: [["Fossil Fuels","Fossil Fuels","Fossil Fuels","Fossil Fuels","Fossil Fuels",...,"Renewables","Renewables","Renewables","Renewables","Renewables"]]
234229
net_generation: [[35361,35991,36234,36205,36883,...,16476,17452,19091,21241,21933]]
230+
231+
.. _Path.stem:
232+
https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.stem
233+
.. _Path.suffix:
234+
https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.suffix
235235
"""
236236
return self._reader.dataset(name, suffix, **kwds)
237237

@@ -261,16 +261,16 @@ def url(
261261
262262
Examples
263263
--------
264-
The returned url will always point to an accessible dataset:
264+
The returned url will always point to an accessible dataset::
265265
266266
import altair as alt
267267
from altair.datasets import Loader
268268
269269
load = Loader.from_backend("polars")
270-
>>> load.url("cars") # doctest: +SKIP
271-
'https://cdn.jsdelivr.net/npm/vega-datasets@v2.11.0/data/cars.json'
270+
load.url("cars")
271+
"https://cdn.jsdelivr.net/npm/vega-datasets@v2.11.0/data/cars.json"
272272
273-
We can pass the result directly to a chart:
273+
We can pass the result directly to a chart::
274274
275275
url = load.url("cars")
276276
alt.Chart(url).mark_point().encode(x="Horsepower:Q", y="Miles_per_Gallon:Q")
@@ -282,19 +282,19 @@ def cache(self) -> DatasetCache[IntoDataFrameT, IntoFrameT]:
282282
"""
283283
Caching of remote dataset requests.
284284
285-
Configure cache path:
285+
Configure cache path::
286286
287287
self.cache.path = "..."
288288
289-
Download the latest datasets *ahead-of-time*:
289+
Download the latest datasets *ahead-of-time*::
290290
291291
self.cache.download_all()
292292
293-
Remove all downloaded datasets:
293+
Remove all downloaded datasets::
294294
295295
self.cache.clear()
296296
297-
Disable caching:
297+
Disable caching::
298298
299299
self.cache.path = None
300300
"""

doc/user_guide/api.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,5 +791,21 @@ Typing
791791
Optional
792792
is_chart_type
793793

794+
.. _api-datasets:
795+
796+
Datasets
797+
--------
798+
.. currentmodule:: altair.datasets
799+
800+
.. autosummary::
801+
:toctree: generated/datasets/
802+
:nosignatures:
803+
804+
Loader
805+
load
806+
url
807+
794808
.. _Generic:
795809
https://typing.readthedocs.io/en/latest/spec/generics.html#generics
810+
.. _vega-datasets:
811+
https://github.com/vega/vega-datasets

tools/generate_api_docs.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,22 @@
110110
111111
{typing_objects}
112112
113+
.. _api-datasets:
114+
115+
Datasets
116+
--------
117+
.. currentmodule:: altair.datasets
118+
119+
.. autosummary::
120+
:toctree: generated/datasets/
121+
:nosignatures:
122+
123+
{datasets_objects}
124+
113125
.. _Generic:
114126
https://typing.readthedocs.io/en/latest/spec/generics.html#generics
127+
.. _vega-datasets:
128+
https://github.com/vega/vega-datasets
115129
"""
116130

117131

@@ -171,6 +185,10 @@ def theme() -> list[str]:
171185
return sort_3
172186

173187

188+
def datasets() -> list[str]:
189+
return alt.datasets.__all__
190+
191+
174192
def lowlevel_wrappers() -> list[str]:
175193
objects = sorted(iter_objects(alt.schema.core, restrict_to_subclass=alt.SchemaBase))
176194
# The names of these two classes are also used for classes in alt.channels. Due to
@@ -194,6 +212,7 @@ def write_api_file() -> None:
194212
api_classes=sep.join(api_classes()),
195213
typing_objects=sep.join(type_hints()),
196214
theme_objects=sep.join(theme()),
215+
datasets_objects=sep.join(datasets()),
197216
),
198217
encoding="utf-8",
199218
)

0 commit comments

Comments
 (0)