From a7f1b7c9e2a2775f287e460dc12d2e8b54abd96e Mon Sep 17 00:00:00 2001 From: "Malte J. Ziebarth" Date: Sun, 4 Aug 2024 22:41:39 +0200 Subject: [PATCH] Fix check in Quantity not accepting integers as scalars. --- README.md | 4 ++++ cyantities/quantity.pyx | 2 +- meson.build | 2 +- pyproject.toml | 2 +- testing/test_quantities.py | 4 ++++ 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ce9d60d..9743122 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,10 @@ This software is licensed under the European Public License (EUPL) version 1.2 o The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +### [0.2.1] - 2024-08-04 +#### Changed +- Fix check in `Quantity` not considering integers as valid scalars. + ### [0.2.0] - 2024-08-04 #### Added - Add `shape` method for `Quantity`, which allows to query the (array-) shape diff --git a/cyantities/quantity.pyx b/cyantities/quantity.pyx index 925d043..d86bdc7 100644 --- a/cyantities/quantity.pyx +++ b/cyantities/quantity.pyx @@ -256,7 +256,7 @@ cdef class Quantity: cdef double d_value cdef bool is_scalar cdef object val_object - if isinstance(value, float): + if isinstance(value, float) or isinstance(value, int): is_scalar = True d_value = value val_object = None diff --git a/meson.build b/meson.build index 6e47811..a39f973 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,5 @@ project('cyantities', 'cpp', 'cython', - version : '0.2.0', default_options : ['optimization=3']) + version : '0.2.1', default_options : ['optimization=3']) # diff --git a/pyproject.toml b/pyproject.toml index 4b52390..8249179 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "Cyantities" -version = "0.2.0" +version = "0.2.1" authors = [ {name = "Malte J. Ziebarth", email = "mjz.science@fmvkb.de"}, ] diff --git a/testing/test_quantities.py b/testing/test_quantities.py index ecf80ad..1885f67 100644 --- a/testing/test_quantities.py +++ b/testing/test_quantities.py @@ -29,11 +29,15 @@ def test_quantity(): q0 = Quantity(1.0, "m") q1 = Quantity(np.array([1.0, 2.0, 3.0]), 'm') q3 = Quantity(2.0, "kg") + q0_1 = Quantity(1, "m") # Shapes: assert q0.shape() == q3.shape() == 1 assert q1.shape() == (3,) + # Equality of float <-> int as scalar: + assert q0 == q0_1 + # Multiplication: q2 = q0 * q1 assert q2.unit() == Unit("m^2")