Skip to content

Commit a7f1b7c

Browse files
committed
Fix check in Quantity not accepting integers as scalars.
1 parent 7d07eef commit a7f1b7c

File tree

5 files changed

+11
-3
lines changed

5 files changed

+11
-3
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ This software is licensed under the European Public License (EUPL) version 1.2 o
172172
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
173173
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
174174

175+
### [0.2.1] - 2024-08-04
176+
#### Changed
177+
- Fix check in `Quantity` not considering integers as valid scalars.
178+
175179
### [0.2.0] - 2024-08-04
176180
#### Added
177181
- Add `shape` method for `Quantity`, which allows to query the (array-) shape

cyantities/quantity.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ cdef class Quantity:
256256
cdef double d_value
257257
cdef bool is_scalar
258258
cdef object val_object
259-
if isinstance(value, float):
259+
if isinstance(value, float) or isinstance(value, int):
260260
is_scalar = True
261261
d_value = value
262262
val_object = None

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
project('cyantities', 'cpp', 'cython',
2-
version : '0.2.0', default_options : ['optimization=3'])
2+
version : '0.2.1', default_options : ['optimization=3'])
33

44

55
#

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "Cyantities"
7-
version = "0.2.0"
7+
version = "0.2.1"
88
authors = [
99
{name = "Malte J. Ziebarth", email = "mjz.science@fmvkb.de"},
1010
]

testing/test_quantities.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@ def test_quantity():
2929
q0 = Quantity(1.0, "m")
3030
q1 = Quantity(np.array([1.0, 2.0, 3.0]), 'm')
3131
q3 = Quantity(2.0, "kg")
32+
q0_1 = Quantity(1, "m")
3233

3334
# Shapes:
3435
assert q0.shape() == q3.shape() == 1
3536
assert q1.shape() == (3,)
3637

38+
# Equality of float <-> int as scalar:
39+
assert q0 == q0_1
40+
3741
# Multiplication:
3842
q2 = q0 * q1
3943
assert q2.unit() == Unit("m^2")

0 commit comments

Comments
 (0)