Skip to content

Commit

Permalink
Update si-units to v0.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
prehner committed Dec 5, 2024
1 parent 00fbc36 commit bc9a097
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 43 deletions.
2 changes: 1 addition & 1 deletion si-units/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "si-units"
version = "0.9.1"
version = "0.10.0"
authors = [
"Philipp Rehner <[email protected]>",
"Gernot Bauer <[email protected]>",
Expand Down
31 changes: 0 additions & 31 deletions si-units/src/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::*;
use ndarray::Dimension;
use regex::Regex;
use std::cmp::Ordering;
use std::collections::HashMap;
Expand Down Expand Up @@ -187,19 +186,6 @@ fn unit_to_latex_product(vec: Vec<(&str, i8)>) -> Option<String> {
}
}

impl<D: Dimension> fmt::Display for SIArray<'_, D> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match DERIVED_UNITS.get(&self.unit) {
Some((unit, symbol, _, _, _)) => {
write!(f, "{} {}", &self.value / unit.value, symbol)
}
None => {
write!(f, "{} {}", self.value, self.unit)
}
}
}
}

impl fmt::Display for Debye {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{} De", self.0)
Expand Down Expand Up @@ -390,20 +376,3 @@ static PREFIX_SYMBOLS: LazyLock<HashMap<i8, &'static str>> = LazyLock::new(|| {
m.insert(24, "Y");
m
});

// #[cfg(test)]
// mod tests {
// use super::*;

// #[test]
// fn test_fmt_si() {
// assert_eq!(format!("{:.3}", RGAS), "8.314 J/mol/K");
// }

// #[test]
// fn test_fmt_zero() {
// assert_eq!(format!("{}", 0.0 * KELVIN), "0 K");
// assert_eq!(format!("{:.2}", 0.0 * PASCAL), "0.00 Pa");
// assert_eq!((0.0 * KELVIN).to_latex(), "0\\,\\mathrm{K}");
// }
// }
13 changes: 2 additions & 11 deletions si-units/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![warn(clippy::all)]
#![allow(non_snake_case)]
use ndarray::{arr1, Array1, ArrayView};
use numpy::{IntoPyArray, PyReadonlyArray1, PyReadonlyArray2, PyReadonlyArray3, PyReadonlyArray4};
use ndarray::{arr1, Array1};
use numpy::IntoPyArray;
use pyo3::basic::CompareOp;
use pyo3::exceptions::PyRuntimeError;
use pyo3::prelude::*;
Expand Down Expand Up @@ -77,14 +77,6 @@ impl PySIObject {
fn __repr__(&self, py: Python) -> PyResult<String> {
if let Ok(v) = self.value.extract::<f64>(py) {
Ok(SINumber::new(v, self.unit).to_string())
} else if let Ok(v) = self.value.extract::<PyReadonlyArray1<f64>>(py) {
Ok(SIArray::new(v.as_array(), self.unit).to_string())
} else if let Ok(v) = self.value.extract::<PyReadonlyArray2<f64>>(py) {
Ok(SIArray::new(v.as_array(), self.unit).to_string())
} else if let Ok(v) = self.value.extract::<PyReadonlyArray3<f64>>(py) {
Ok(SIArray::new(v.as_array(), self.unit).to_string())
} else if let Ok(v) = self.value.extract::<PyReadonlyArray4<f64>>(py) {
Ok(SIArray::new(v.as_array(), self.unit).to_string())
} else {
let value = self
.value
Expand Down Expand Up @@ -312,7 +304,6 @@ pub struct SIObject<T> {
}

pub type SINumber = SIObject<f64>;
pub type SIArray<'a, D> = SIObject<ArrayView<'a, f64, D>>;

impl<T> SIObject<T> {
pub const fn new(value: T, unit: SIUnit) -> Self {
Expand Down

0 comments on commit bc9a097

Please sign in to comment.