Skip to content

Commit b83380d

Browse files
authored
Merge pull request #1 from predict-idlab/release
📦 fix setup.py + 🐛 some bug fixes + 🤖 package CI-CD
2 parents 7aeef0f + 342084a commit b83380d

File tree

14 files changed

+497
-170
lines changed

14 files changed

+497
-170
lines changed
Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
name: CI tsdownsample
22

33
on:
4-
pull_request:
4+
pull_request: {}
55
push:
66
branches:
77
- main
8+
tags:
9+
- '**'
810

911
defaults:
1012
run:
1113
shell: bash
1214

1315
jobs:
14-
Check:
16+
17+
Lint_and_Check:
1518
runs-on: ubuntu-latest
1619
steps:
17-
- name: Checkout
18-
uses: actions/checkout@v2
20+
- uses: actions/checkout@v3
21+
- uses: actions/setup-python@v4
22+
with:
23+
python-version: '3.10'
24+
- run: pip install -r tests/requirements-linting.txt
1925

2026
- name: Install Rust toolchain
2127
uses: actions-rs/toolchain@v1
@@ -27,15 +33,11 @@ jobs:
2733
run: |
2834
rustup update nightly --no-self-update
2935
rustup default nightly
36+
- name: Cache rust
37+
uses: Swatinem/rust-cache@v2
3038

31-
- name: Rust toolchain info
32-
run: |
33-
cargo --version --verbose
34-
rustc --version
35-
cargo clippy --version
36-
cargo fmt --version
37-
38-
- name: check
39-
run: cargo check --verbose
40-
- name: formatting check
41-
run: cargo fmt --all -- --check
39+
- run: pip freeze
40+
- run: make lint # Lint Python & Rust
41+
- run: make mypy # Type check Python
42+
43+
# https://github.com/samuelcolvin/rtoml/blob/main/.github/workflows/ci.yml

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
venv/
12
TODO.md
23
main.rs
34

Makefile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
.DEFAULT_GOAL := all
2+
isort = isort tsdownsample tests
3+
black = black tsdownsample tests
4+
5+
6+
.PHONY: format
7+
format:
8+
$(isort)
9+
$(black)
10+
cargo fmt
11+
12+
.PHONY: lint-python
13+
lint-python:
14+
ruff tsdownsample tests
15+
$(isort) --check-only --df
16+
$(black) --check --diff
17+
18+
.PHONY: lint-rust
19+
lint-rust:
20+
cargo fmt --version
21+
cargo fmt --all -- --check
22+
cargo clippy --version
23+
cargo clippy -- -D warnings -A incomplete_features -W clippy::dbg_macro -W clippy::print_stdout
24+
25+
.PHONY: lint
26+
lint: lint-python lint-rust
27+
28+
.PHONY: mypy
29+
mypy:
30+
mypy tsdownsample
31+
32+
.PHONY: all
33+
all: lint mypy testcov
34+
35+
.PHONY: clean
36+
clean:
37+
rm -rf `find . -name __pycache__`
38+
rm -f `find . -type f -name '*.py[co]' `
39+
rm -f `find . -type f -name '*~' `
40+
rm -f `find . -type f -name '.*~' `
41+
rm -rf dist
42+
rm -rf build
43+
rm -rf target
44+
rm -rf .cache
45+
rm -rf .pytest_cache
46+
rm -rf .mypy_cache
47+
rm -rf htmlcov
48+
rm -rf *.egg-info
49+
rm -f .coverage
50+
rm -f .coverage.*
51+
rm -rf build
52+
rm -f tsdownsample/*.so
53+
python setup.py clean

downsample_rs/src/lttb/scalar.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,22 @@ pub fn lttb_without_x<Ty: Num>(y: ArrayView1<Ty>, n_out: usize) -> Array1<usize>
104104
// Slicing seems to be a lot slower
105105
// let avg_x: Tx = x.slice(s![avg_range_start..avg_range_end]).sum();
106106
let avg_y: f64 = avg_y.to_f64() / (avg_range_end - avg_range_start) as f64;
107+
let avg_x: f64 = (avg_range_start + avg_range_end - 1) as f64 / 2.0;
107108

108109
// Get the range for this bucket
109110
let range_offs = (every * i as f64) as usize + 1;
110111
let range_to = (every * (i + 1) as f64) as usize + 1;
111112

112113
// Point a
113114
let point_ay = y[a].to_f64();
115+
let point_ax = a as f64;
114116

115117
let mut max_area = -1.0;
116118
for i in range_offs..range_to {
117119
// Calculate triangle area over three buckets
118-
let area = ((y[i].to_f64() - point_ay) - (avg_y - point_ay)).abs();
120+
let area = ((point_ax - avg_x) * (y[i].to_f64() - point_ay)
121+
- (point_ax - i as f64) * (avg_y - point_ay))
122+
.abs();
119123
if area > max_area {
120124
max_area = area;
121125
a = i;
@@ -167,13 +171,9 @@ mod tests {
167171
let n = 5_000;
168172
let x: Array1<i32> = Array1::from((0..n).map(|i| i as i32).collect::<Vec<i32>>());
169173
let y = utils::get_random_array(n, f32::MIN, f32::MAX);
170-
let sampled_indices = lttb(x.view(), y.view(), 200);
174+
let sampled_indices1 = lttb(x.view(), y.view(), 200);
171175
let sampled_indices2 = lttb_without_x(y.view(), 200);
172-
// TODO: for some reason the second last point is off..
173-
assert_eq!(
174-
sampled_indices.slice(s![0..198]),
175-
sampled_indices2.slice(s![0..198])
176-
);
176+
assert_eq!(sampled_indices1, sampled_indices2);
177177
}
178178
}
179179
}

poetry.lock

Lines changed: 0 additions & 131 deletions
This file was deleted.

pyproject.toml

Lines changed: 64 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,71 @@
1-
[tool.poetry]
1+
[build-system]
2+
requires = ["setuptools", "wheel", "setuptools-rust"]
3+
4+
[project]
25
name = "tsdownsample"
3-
version = "0.1.0a0"
6+
version = "0.1.0a1"
7+
requires-python = ">=3.7"
48
description = "Time series downsampling in rust"
5-
authors = ["Jeroen Van Der Donckt"]
9+
authors = [{name = "Jeroen Van Der Donckt"}]
610
readme = "README.md"
7-
license = "MIT"
8-
repository = "https://github.com/predict-idlab/tsdownsample"
11+
license = {text = "MIT"}
912
keywords = ["time series", "downsampling", "rust", "data science", "visualization"]
13+
classifiers = [
14+
'Intended Audience :: Developers',
15+
'License :: OSI Approved :: MIT License',
16+
'Intended Audience :: Developers',
17+
'Programming Language :: Python :: 3',
18+
'Programming Language :: Python :: 3.6', # TODO?
19+
'Programming Language :: Python :: 3.7',
20+
'Programming Language :: Python :: 3.8',
21+
'Programming Language :: Python :: 3.9',
22+
'Programming Language :: Python :: 3.10',
23+
'Programming Language :: Python :: 3.11',
24+
'Operating System :: POSIX',
25+
'Operating System :: MacOS :: MacOS X',
26+
'Operating System :: Microsoft :: Windows'
27+
]
28+
29+
[project.urls]
30+
homepage = "https://github.com/predict-idlab/tsdownsample"
31+
repository = "https://github.com/predict-idlab/tsdownsample"
1032

11-
[tool.poetry.dependencies]
12-
python = "^3.7.1"
13-
numpy = ">=1.21"
14-
pandas = ">=1.3"
33+
# Build Python bindings for rust
34+
[tool.maturin]
35+
bindings = "pyo3"
1536

16-
[tool.poetry.dev-dependencies]
37+
# Linting
38+
[tool.ruff]
39+
line-length = 88
40+
extend-select = ["Q"]
41+
ignore = ["E402", "F403"]
1742

18-
[build-system]
19-
requires = ["poetry-core>=1.0.0"]
20-
build-backend = "poetry.core.masonry.api"
43+
# Formatting
44+
[tool.black]
45+
color = true
46+
line-length = 88
47+
skip-string-normalization = true
48+
skip-magic-trailing-comma = true
49+
50+
# Sort imports
51+
[tool.isort]
52+
line_length = 88
53+
known_first_party = ["tsdownsample"]
54+
multi_line_output = 3
55+
include_trailing_comma = true
56+
force_grid_wrap = 0
57+
combine_as_imports = true
58+
color_output = true
59+
skip = "tests/toml_test.py"
60+
61+
# Static typing
62+
[tool.mypy]
63+
follow_imports = "normal"
64+
strict_optional = true
65+
warn_redundant_casts = true
66+
warn_unused_ignores = true
67+
check_untyped_defs = true
68+
no_implicit_reexport = true
69+
disallow_untyped_defs = true
70+
disallow_any_generics = false
71+
ignore_missing_imports = true

requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
numpy
2+
pandas
3+
# Build dependencies
4+
setuptools_rust

0 commit comments

Comments
 (0)