diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 94541e4..21ee43f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - uses: Swatinem/rust-cache@v1 - uses: actions-rs/toolchain@v1 with: profile: minimal @@ -26,6 +27,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - uses: Swatinem/rust-cache@v1 - uses: actions-rs/toolchain@v1 with: profile: minimal @@ -43,6 +45,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - uses: Swatinem/rust-cache@v1 - uses: actions-rs/toolchain@v1 with: profile: minimal @@ -65,5 +68,5 @@ jobs: - name: Run pre-commit hooks run: | pip install pre-commit \ - && pre-commit run --all + && pre-commit run --all-files diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bdb654d..d916215 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,13 +11,13 @@ repos: types: [rust] - repo: https://github.com/timothycrosley/isort - rev: 5.9.3 + rev: 5.10.1 hooks: - id: isort stages: [commit] - repo: https://github.com/ambv/black - rev: 21.9b0 + rev: 22.3.0 hooks: - id: black language_version: python3 @@ -31,20 +31,20 @@ repos: stages: [commit] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.910-1 + rev: v0.942 hooks: - id: mypy - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks - rev: v2.2.0 + rev: v2.3.0 hooks: - id: pretty-format-yaml - args: [--autofix] + args: [--autofix, --preserve-quotes] - id: pretty-format-toml args: [--autofix] - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.0.1 + rev: v4.2.0 hooks: - id: check-added-large-files - id: check-ast diff --git a/ndhistogram/CHANGELOG.md b/ndhistogram/CHANGELOG.md index e6147d0..fc4ceab 100644 --- a/ndhistogram/CHANGELOG.md +++ b/ndhistogram/CHANGELOG.md @@ -1,3 +1,8 @@ +# 0.6.3 (2022-04-07) +- `Uniform::with_step_size` now panics when given a step size equal to zero (from [@jacg](https://github.com/jacg)). +- Documentation and CI improvements from [@jacg](https://github.com/jacg). +- Fix compiler/clippy warnings when building with the latest stable version (clippy 0.1.59, rustc 1.59.0). + # 0.6.2 (2021-10-16) - Fix for compiler/clippy warnings when building with the latest stable version (clippy 0.1.55, rustc 1.55.0). diff --git a/ndhistogram/Cargo.toml b/ndhistogram/Cargo.toml index e2dcfc7..b6d8403 100644 --- a/ndhistogram/Cargo.toml +++ b/ndhistogram/Cargo.toml @@ -25,7 +25,7 @@ bench = false [package] name = "ndhistogram" -version = "0.6.2" +version = "0.6.3" authors = [ "David Hadley ",] edition = "2018" license = "MIT OR Apache-2.0" diff --git a/ndhistogram/README.md b/ndhistogram/README.md index 122c355..6724852 100644 --- a/ndhistogram/README.md +++ b/ndhistogram/README.md @@ -30,7 +30,7 @@ Add this to your `Cargo.toml`: ```toml [dependencies] -ndhistogram = "0.6.2" +ndhistogram = "0.6.3" ``` See the [change log](https://github.com/davehadley/ndhistogram/blob/main/ndhistogram/CHANGELOG.md) diff --git a/ndhistogram/src/axis/uniform.rs b/ndhistogram/src/axis/uniform.rs index 713a4bb..050dc84 100644 --- a/ndhistogram/src/axis/uniform.rs +++ b/ndhistogram/src/axis/uniform.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; /// An axis with equal sized bins. /// -/// An axis with N equally spaced, equal sized, bins between (low, high]. +/// An axis with N equally spaced, equal sized, bins between [low, high). /// Below (above) this range is an underflow (overflow) bin. /// Hence this axis has N+2 bins. /// @@ -65,14 +65,14 @@ where /// Factory method to create an axis with num uniformly spaced bins in the range [low, low+num*step). Under/overflow bins cover values outside this range. /// /// # Panics - /// Panics if num bins == 0 or step < 0. + /// Panics if num bins == 0 or step <= 0. pub fn with_step_size(num: usize, low: T, step: T) -> Self { let high = T::from(num).expect("num bins can be converted to coordinate type") * step + low; if num == 0 { panic!("Invalid axis num bins ({})", num); } - if step < T::zero() { - panic!("Invalid negative step size"); + if step <= T::zero() { + panic!("Invalid step size. Step size must be greater than zero."); } let (low, high) = if low > high { (high, low) } else { (low, high) }; Self { diff --git a/ndhistogram/src/axis/uniformnoflow.rs b/ndhistogram/src/axis/uniformnoflow.rs index b8ba031..28b0f3b 100644 --- a/ndhistogram/src/axis/uniformnoflow.rs +++ b/ndhistogram/src/axis/uniformnoflow.rs @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize}; /// An axis with equal sized bins and no under/overflow bins. /// -/// An axis with N equally spaced, equal sized, bins between (low, high]. +/// An axis with N equally spaced, equal sized, bins between [low, high). /// Similar to [Uniform] but this axis has no over/underflow bins. /// Hence it has N bins. /// diff --git a/ndhistogram/src/lib.rs b/ndhistogram/src/lib.rs index a984874..fd5a4e5 100644 --- a/ndhistogram/src/lib.rs +++ b/ndhistogram/src/lib.rs @@ -19,7 +19,7 @@ //! //! ```toml //! [dependencies] -//! ndhistogram = "0.6.2" +//! ndhistogram = "0.6.3" //! ``` //! //! See the [change log](https://github.com/davehadley/ndhistogram/blob/main/ndhistogram/CHANGELOG.md) @@ -128,7 +128,7 @@ //! User defined bin value types are possible by implementing the [Fill](Fill), [FillWith](FillWith) or [FillWithWeighted](FillWithWeighted) traits. #![doc(issue_tracker_base_url = "https://github.com/davehadley/rust-hist/issues")] -#![doc(html_root_url = "https://docs.rs/ndhistogram/0.6.2")] +#![doc(html_root_url = "https://docs.rs/ndhistogram/0.6.3")] #![cfg_attr( debug_assertions, warn( diff --git a/ndhistogram/tests/test_uniform_axis.rs b/ndhistogram/tests/test_uniform_axis.rs index 9a2d79b..f667b3c 100644 --- a/ndhistogram/tests/test_uniform_axis.rs +++ b/ndhistogram/tests/test_uniform_axis.rs @@ -35,8 +35,7 @@ fn test_uniform_get_bin() { fn test_uniform_get_edges() { let ax = Uniform::new(5, 0.0, 1.0); let actual: Vec> = Range:: { start: -2, end: 7 } - .map(|x| ax.bin(x as usize)) - .flatten() + .filter_map(|x| ax.bin(x as usize)) .filter_map(|x| Range::try_from(x).ok()) .collect(); let edges: Vec = vec![0.0, 0.2, 0.4, 0.6, 0.8, 1.0]; diff --git a/ndhistogram/tests/test_uniform_axis_integer.rs b/ndhistogram/tests/test_uniform_axis_integer.rs index 31c201c..59ad7bf 100644 --- a/ndhistogram/tests/test_uniform_axis_integer.rs +++ b/ndhistogram/tests/test_uniform_axis_integer.rs @@ -28,3 +28,15 @@ fn test_uniform_integer_get_bin() { ]; assert_eq!(expected, actual); } + +#[test] +#[should_panic] +fn test_uniform_with_step_size_should_panic_on_negative_step() { + Uniform::with_step_size(10, 20.0, -1.0); +} + +#[test] +#[should_panic] +fn test_uniform_with_step_size_should_panic_on_zero_step() { + Uniform::with_step_size(10, 20.0, 0.0); +} diff --git a/ndhistogram/tests/test_variablenoflow_axis.rs b/ndhistogram/tests/test_variablenoflow_axis.rs index 2a8ef64..498ba7f 100644 --- a/ndhistogram/tests/test_variablenoflow_axis.rs +++ b/ndhistogram/tests/test_variablenoflow_axis.rs @@ -41,7 +41,7 @@ fn test_variablenoflow_high() { #[test] fn test_variablenoflow_get_index() { let ax = VariableNoFlow::new(vec![0, 1, 4, 8]); - let actual: Vec<_> = (-1..10).map(|coord| ax.index(&coord)).flatten().collect(); + let actual: Vec<_> = (-1..10).filter_map(|coord| ax.index(&coord)).collect(); let expected = vec![0, 1, 1, 1, 2, 2, 2, 2]; assert_eq!(actual, expected); } @@ -108,7 +108,7 @@ fn test_variablenoflow_iterate_items() { #[test] fn test_negative_axis_index() { let axis = VariableNoFlow::new(vec![-3, -1, 0, 1]); - let actual: Vec<_> = (-4..3).map(|loc| axis.index(&loc)).flatten().collect(); + let actual: Vec<_> = (-4..3).filter_map(|loc| axis.index(&loc)).collect(); let expected = vec![0, 0, 1, 2]; assert_eq!(actual, expected) }