Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/numpy2.0 #10

Merged
merged 6 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/linux-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
max-parallel: 5
matrix:
python-version: [3.8, 3.9, '3.10', '3.11', '3.12']
python-version: [3.9, '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v4
- name: Setup base conda for Python 3.11
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:
eval "$($CONDA_EXE shell.bash activate test-environment)"
which python
cd cythonarrays
pip install sphinx sphinxcontrib-napoleon sphinx-autodoc-typehints 'mistune<2' m2r2
pip install sphinx sphinxcontrib-napoleon sphinx-autodoc-typehints 'mistune<2' m2r2 'docutils<0.20' pytest
sphinx-apidoc -f --separate -o docs_rst/cythonarrays src/cythonarrays
sphinx-build docs_rst ../docs

Expand Down
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Changelog


## [Unreleased]

### Added


### Changed


### Removed


## [1.6.2] - 2024-08-19

### Added

- CHANGELOG.md

### Fixed

### Changed
- update to numpy>=2.0
- change definition of NINF_d etc.

### Removed
- support for python 3.8 (does not support numpy 2.0)



[unreleased]: https://github.com/MaxBo/cythonarrays/compare/v1.6.2...HEAD
[1.6.2]: https://github.com/MaxBo/cythonarrays/compare/v1.6.1...v1.6.2
[1.6.1]: https://github.com/MaxBo/cythonarrays/releases/tag/v1.6.1
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# cythonarrays
Python Packages to facilitate cython cdef-classes that expose memoryviews as numpy arrays.

[Changelog](CHANGELOG.md)

##cythonarrays:
[![PyPI version](https://badge.fury.io/py/cythonarrays.svg)](https://badge.fury.io/py/cythonarrays)
[![Anaconda-Server Badge](https://anaconda.org/maxbo/cythonarrays/badges/version.svg)](https://anaconda.org/maxbo/cythonarrays)
Expand Down
2 changes: 1 addition & 1 deletion cythonarrays/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
numpy
numpy>=2.0
cython
xarray
h5netcdf
2 changes: 1 addition & 1 deletion cythonarrays/src/cythonarrays/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.6.1'
__version__ = '1.6.2'
2 changes: 1 addition & 1 deletion cythonarrays/src/cythonarrays/array_descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def shape(self, value: Union[int, str, bytes, Tuple[Union[int, str]]]):
the shape provided as a number, a string
(comma separated for several dimensions) or a tuple/list of strings or ints
"""
if isinstance(value, (int, np.compat.long)):
if isinstance(value, (int, )):
value = (value, )
elif isinstance(value, (str, bytes)):
splitted = value.split(',')
Expand Down
22 changes: 13 additions & 9 deletions cythonarrays/src/cythonarrays/array_shapes.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ from .array_descriptors import ArrayDescriptor
cimport cython
cdef extern from "numpy/npy_math.h":
bint npy_isnan(double x) nogil
double NPY_INFINITY
float NPY_INFINITYF
double NPY_NAN
float NPY_NANF


cdef class ArrayShapes(object):
Expand All @@ -34,19 +38,19 @@ cdef class ArrayShapes(object):

def __init__(self, *args, **kwargs):
"""
inits the Array and creates the constands for NAN and NINF
inits the Array and creates the constants for NAN, INF and NINF
"""
# super class has to be called even if the super class of ArrayShapes
# is only `object`
super().__init__(*args, **kwargs)
# set NAN-Values
self.NAN_f = np.NAN #np.float32(0) / np.float32(0)
self.INF_f = np.float32(1) / np.float32(0)
self.NINF_f = np.float32(-1) / np.float32(0)

self.NAN_d = np.NAN #np.float64(0) / np.float64(0)
self.INF_d = np.float64(1) / np.float64(0)
self.NINF_d = np.float64(-1) / np.float64(0)
#set NAN-Values
self.NAN_f = NPY_NANF
self.INF_f = NPY_INFINITYF
self.NINF_f = -NPY_INFINITYF

self.NAN_d = NPY_NAN
self.INF_d = NPY_INFINITY
self.NINF_d = -NPY_INFINITY

cdef char _isnan(self, np_floating x) nogil:
"""
Expand Down
8 changes: 4 additions & 4 deletions cythonarrays/src/cythonarrays/tests/test_cythonarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def test_33_del_property(self):

# reset to default (not defined)
example.reset_array('km_ij')
np.testing.assert_array_equal(example.km_ij, np.NAN)
np.testing.assert_array_equal(example.km_ij, np.nan)

# reset to default (new value defined)
example.dtypes['km_ij'].default = 11
Expand Down Expand Up @@ -449,9 +449,9 @@ def test042_test_nan(self, persons_gi: np.ndarray):
groups, zones = persons_gi.shape
example = Example(groups, zones)

assert example.isnan_py(np.NAN)
assert not example.isnan_py(np.NINF)
assert not example.isnan_py(np.Inf)
assert example.isnan_py(np.nan)
assert not example.isnan_py(-np.inf)
assert not example.isnan_py(np.inf)
assert not example.isnan_py(0)
assert not example.isnan_py(1)
assert not example.isnan_py(-1)
Expand Down
Loading