Skip to content

Commit

Permalink
MAINT: add doctests to travis CI; minor fixes so they pass
Browse files Browse the repository at this point in the history
  • Loading branch information
jakevdp committed Apr 11, 2018
1 parent 7f1e79a commit f49d599
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ python:
before_install:
- pip install pip --upgrade;
- pip install -r requirements.txt;
- pip install jinja2 sphinx docutils

install:
- python setup.py install;

script:
- flake8 ./;
- python -m pytest --pyargs altair;
- python -m pytest --pyargs --doctest-modules altair;
20 changes: 10 additions & 10 deletions altair/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,28 +202,28 @@ def parse_shorthand(shorthand, data=None):
>>> parse_shorthand('name')
{'field': 'name'}
>>> parse_shorthand('average(col)')
>>> parse_shorthand('average(col)') # doctest: +SKIP
{'aggregate': 'average', 'field': 'col'}
>>> parse_shorthand('foo:O')
>>> parse_shorthand('foo:O') # doctest: +SKIP
{'field': 'foo', 'type': 'ordinal'}
>>> parse_shorthand('min(foo):Q')
>>> parse_shorthand('min(foo):Q') # doctest: +SKIP
{'aggregate': 'min', 'field': 'foo', 'type': 'quantitative'}
>>> parse_shorthand('foo', data)
>>> parse_shorthand('foo', data) # doctest: +SKIP
{'field': 'foo', 'type': 'nominal'}
>>> parse_shorthand('bar', data)
>>> parse_shorthand('bar', data) # doctest: +SKIP
{'field': 'bar', 'type': 'quantitative'}
>>> parse_shorthand('bar:O', data)
>>> parse_shorthand('bar:O', data) # doctest: +SKIP
{'field': 'bar', 'type': 'ordinal'}
>>> parse_shorthand('sum(bar)', data)
>>> parse_shorthand('sum(bar)', data) # doctest: +SKIP
{'aggregate': 'sum', 'field': 'bar', 'type': 'quantitative'}
>>> parse_shorthand('count()', data)
>>> parse_shorthand('count()', data) # doctest: +SKIP
{'aggregate': 'count', 'type': 'quantitative'}
"""
attrs = _parse_shorthand(shorthand)
Expand Down Expand Up @@ -305,9 +305,9 @@ def update_nested(original, update, copy=False):
--------
>>> original = {'x': {'b': 2, 'c': 4}}
>>> update = {'x': {'b': 5, 'd': 6}, 'y': 40}
>>> update_nested(original, update)
>>> update_nested(original, update) # doctest: +SKIP
{'x': {'b': 5, 'c': 4, 'd': 6}, 'y': 40}
>>> original
>>> original # doctest: +SKIP
{'x': {'b': 5, 'c': 4, 'd': 6}, 'y': 40}
"""
if copy:
Expand Down
2 changes: 1 addition & 1 deletion altair/utils/schemapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def __setitem__(self, item, val):
def __repr__(self):
if self._kwds:
args = ("{0}: {1!r}".format(key, val)
for key, val in self._kwds.items()
for key, val in sorted(self._kwds.items())
if val is not Undefined)
args = '\n' + ',\n'.join(args)
return "{0}({{{1}\n}})".format(self.__class__.__name__,
Expand Down
18 changes: 9 additions & 9 deletions altair/vegalite/v2/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ def transform_aggregate(self, aggregate=Undefined, groupby=Undefined, **kwds):
... mean_acc='mean(Acceleration)',
... groupby=['Origin']
... )
>>> print(chart1.transform[0].to_json())
>>> print(chart1.transform[0].to_json()) # doctest: +NORMALIZE_WHITESPACE
{
"aggregate": [
{
Expand Down Expand Up @@ -552,20 +552,20 @@ def transform_bin(self, as_=Undefined, field=Undefined, bin=True, **kwargs):
>>> chart = alt.Chart().transform_bin("x_binned", "x")
>>> chart.transform[0]
BinTransform({
as: 'x_binned',
bin: True,
field: 'x',
as: 'x_binned'
field: 'x'
})
>>> chart = alt.Chart().transform_bin("x_binned", "x",
... bin=alt.Bin(maxbins=10))
>>> chart.transform[0]
BinTransform({
as: 'x_binned',
bin: BinParams({
maxbins: 10
}),
field: 'x',
as: 'x_binned'
field: 'x'
})
See Also
Expand Down Expand Up @@ -607,8 +607,8 @@ def transform_calculate(self, as_=Undefined, calculate=Undefined, **kwargs):
>>> chart = alt.Chart().transform_calculate(y = 2 * expr.sin(datum.x))
>>> chart.transform[0]
CalculateTransform({
calculate: (2 * sin(datum.x)),
as: 'y'
as: 'y',
calculate: (2 * sin(datum.x))
})
It's also possible to pass the ``CalculateTransform`` arguments directly:
Expand All @@ -617,8 +617,8 @@ def transform_calculate(self, as_=Undefined, calculate=Undefined, **kwargs):
>>> chart = alt.Chart().transform_calculate(**kwds)
>>> chart.transform[0]
CalculateTransform({
calculate: '2 * sin(datum.x)',
as: 'y'
as: 'y',
calculate: '2 * sin(datum.x)'
})
As the first form is easier to write and understand, that is the
Expand Down
2 changes: 1 addition & 1 deletion altair/vegalite/v2/examples/anscombe_plot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Anscombes Quartet
Anscombe's Quartet
------------------
This example shows how to use the column channel to make a trellis plot. Anscombe's Quartet is a famous dataset constructed by Francis Anscombe. Common summary statistics are identical for each subset of the data, despite the subsets having vastly different characteristics.
Expand Down
8 changes: 4 additions & 4 deletions altair/vegalite/v2/examples/step_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
----------
This example shows Google's stock price over time.
This uses the "step-after" interpolation scheme.
The full list of interpolation options includes 'linear,
linear-closed’, ‘step’, ‘step-before’, ‘step-after’, ‘basis,
basis-open’, ‘basis-closed’, ‘cardinal’, ‘cardinal-open,
cardinal-closed’, ‘bundle, and monotone.
The full list of interpolation options includes 'linear',
'linear-closed', 'step', 'step-before', 'step-after', 'basis',
'basis-open', 'basis-closed', 'cardinal', 'cardinal-open',
'cardinal-closed', 'bundle', and 'monotone'.
"""
# category: basic charts

Expand Down
2 changes: 1 addition & 1 deletion tools/schemapi/schemapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def __setitem__(self, item, val):
def __repr__(self):
if self._kwds:
args = ("{0}: {1!r}".format(key, val)
for key, val in self._kwds.items()
for key, val in sorted(self._kwds.items())
if val is not Undefined)
args = '\n' + ',\n'.join(args)
return "{0}({{{1}\n}})".format(self.__class__.__name__,
Expand Down

0 comments on commit f49d599

Please sign in to comment.