Generalized indexing, correct formatting for arrays, new constants. - #100
RolfStierle wants to merge 1 commit into
Conversation
prehner
left a comment
There was a problem hiding this comment.
Thanks! I like the generalized indexing, that will make a lot of scripts much easier. Not sure what problem you are addressing with the formating, though?
| if let Ok(v) = value.extract::<SINumber>() { | ||
| if self.unit == v.unit { | ||
| self.value.call_method1(py, "__setitem__", (idx, v.value))?; | ||
| return Ok(()); | ||
| } | ||
| return Err(QuantityError::InconsistentUnits { | ||
| unit1: self.unit, | ||
| unit2: v.unit, | ||
| } | ||
| .into()); | ||
| } |
There was a problem hiding this comment.
| if let Ok(v) = value.extract::<SINumber>() { | |
| if self.unit == v.unit { | |
| self.value.call_method1(py, "__setitem__", (idx, v.value))?; | |
| return Ok(()); | |
| } | |
| return Err(QuantityError::InconsistentUnits { | |
| unit1: self.unit, | |
| unit2: v.unit, | |
| } | |
| .into()); | |
| } |
I don't think that does anything.
| &self, | ||
| py: Python, | ||
| idx: &Bound<'_, PyAny>, | ||
| value: &Bound<'_, PyAny>, |
There was a problem hiding this comment.
| value: &Bound<'_, PyAny>, | |
| value: &PySIObject, |
There was a problem hiding this comment.
We only need SINumber if we want to make sure that we can only pass a scalar (e.g., in linspace). With the more general indexing, we can simply pass any SI object.
|
|
||
| ## [Unreleased] | ||
| ### Added | ||
| - Electric and Coulomb constants added. [#47](https://github.com/itt-ustutt/quantity/issues/47) |
There was a problem hiding this comment.
link to the PR, not the issue
|
|
||
| ## [Unreleased] | ||
| ### Fixed | ||
| - Correctly formats output of arrays with a unit. |
| - Correctly formats output of arrays with a unit. | ||
|
|
||
| ### Added | ||
| - Getter and Setter generalized to common NumPy indexing, such that general slicing operations are possible in multiple dimensions. |
There was a problem hiding this comment.
| - Getter and Setter generalized to common NumPy indexing, such that general slicing operations are possible in multiple dimensions. | |
| - Indexing generalized, such that, e.g., general multidimensional slicing operations are possible for quantities containing NumPy arrays. |
| pub(crate) trait PrintUnit { | ||
| const UNIT: &'static str; | ||
|
|
||
| fn scale() -> f64; |
| .call_method0(py, "__repr__")? | ||
| .extract::<String>(py)?; | ||
| Ok(format!("{} {}", value, self.unit)) | ||
| let (multiplier, symbol) = SINumber::new(1.0, self.unit).into_scaled_parts(); |
There was a problem hiding this comment.
Is this for the annoying thing with grams and kilograms? I'm not sure I follow here.
|
The changes are implemented in individual PRs, so I am closing this one. |

Corrected error where arrays with units show a unit but only the underlying stored data in basic SI units is shown (confusing when using Jupyter notebooks, underlying data is correct, just wrongly shown).
Indexing generalized such that sliding operations
array[:, 1:3]are now possible for multiple-dimensional arrays.Added electric and Coulomb constants (#47, @g-bauer) and added derived units ATM and POISE (#46, @g-bauer).