M Makefile => Makefile +1 -0
@@ 36,6 36,7 @@ lint:
flake8 src tests
black --check .
isort --check src tests
+ pydocstyle src
test:
pytest -n 2
M requirements-dev.txt => requirements-dev.txt +1 -0
@@ 5,6 5,7 @@ flake8-bugbear
hypothesis[numpy]
isort
pep8-naming
+pydocstyle
pytest
pytest-xdist
tox
M src/lttb/__init__.py => src/lttb/__init__.py +1 -0
@@ 1,1 1,2 @@
+"""Steinarsson's LTTB algorithm (Numpy implementation)."""
from .lttb import downsample # noqa
M src/lttb/lttb.py => src/lttb/lttb.py +7 -5
@@ 1,3 1,10 @@
+"""Downsample data using the Largest-Triangle-Three-Buckets algorithm.
+
+Reference
+---------
+Sveinn Steinarsson. 2013. Downsampling Time Series for Visual
+Representation. MSc thesis. University of Iceland.
+"""
import numpy as np
from .validators import (
@@ 30,11 37,6 @@ def _areas_of_triangles(a, bs, c):
def downsample(data, n_out, validators=default_validators):
"""Downsample ``data`` to ``n_out`` points using the LTTB algorithm.
- Reference
- ---------
- Sveinn Steinarsson. 2013. Downsampling Time Series for Visual
- Representation. MSc thesis. University of Iceland.
-
Parameters
----------
data : numpy.array
M src/lttb/validators.py => src/lttb/validators.py +15 -1
@@ 1,7 1,9 @@
+"""Functions to check that input data is in a valid format."""
import numpy as np
def has_two_columns(data):
+ """Raise ValueError if ``data`` is not a 2D array with 2 columns."""
if len(data.shape) != 2:
raise ValueError("data is not a 2D array")
@@ 10,27 12,39 @@ def has_two_columns(data):
def x_is_sorted(data):
+ """Raise ValueError if the first column of ``data`` is not sorted."""
if np.any(data[1:, 0] < data[:-1, 0]):
raise ValueError("data is not sorted on the first column")
def x_is_strictly_increasing(data):
+ """Raise ValueError if 1st column is not strictly increasing.
+
+ I.e. if the first column of ``data`` either is not sorted
+ or it contains repeated (duplicate) values.
+ """
if np.any(data[1:, 0] <= data[:-1, 0]):
raise ValueError("first column is not strictly increasing")
def x_is_regular(data):
+ """Raise ValueError if 1st column of ``data`` is irregularly spaced.
+
+ I.e. if the intervals between successive values in the first column
+ are not constant.
+ """
if len(np.unique(np.diff(data[:, 0]))) != 1:
raise ValueError("first column is not regularly spaced")
def contains_no_nans(data):
+ """Raise ValueError if ``data`` contains any missing/NaN values."""
if np.any(np.isnan(data)):
raise ValueError("data contains NaN values")
def validate(data, validators):
- """Checks an array against each of the given validators.
+ """Check an array against each of the given validators.
All validators are run (rather than failing at the first error)
and their error messages are concatenated into the message for the
M tox.ini => tox.ini +3 -0
@@ 33,3 33,6 @@ ignore = E203,E501,W503
[isort]
profile = black
+
+[pydocstyle]
+convention = numpy