Skip to content

Commit

Permalink
Fix check in Quantity not accepting integers as scalars.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjziebarth committed Aug 4, 2024
1 parent 7d07eef commit a7f1b7c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cyantities/quantity.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
project('cyantities', 'cpp', 'cython',
version : '0.2.0', default_options : ['optimization=3'])
version : '0.2.1', default_options : ['optimization=3'])


#
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
]
Expand Down
4 changes: 4 additions & 0 deletions testing/test_quantities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit a7f1b7c

Please sign in to comment.