Skip to content

Commit cad58c1

Browse files
Revert "MAINT: Minimal changes to get working with numpy 2.0"
This reverts commit 64c597a.
1 parent 64c597a commit cad58c1

File tree

6 files changed

+83
-68
lines changed

6 files changed

+83
-68
lines changed

.github/workflows/tests.yml

+34-34
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
strategy:
88
matrix:
99
python-version: ['3.12', '3.11', '3.10', '3.9']
10-
numpy-version: ['1.20.3', '1.21.6', '1.22.4', '1.23.5', '1.24.4', '1.25.2', '1.26.4', '2.0.0']
10+
numpy-version: ['1.20.3', '1.21.6', '1.22.4', '1.23.5', '1.24.4', '1.25.2', '1.26.4']
1111
exclude:
1212
- python-version: '3.10'
1313
numpy-version: '1.20.3'
@@ -59,7 +59,7 @@ jobs:
5959
strategy:
6060
matrix:
6161
python-version: ['3.12', '3.11', '3.10', '3.9']
62-
numpy-version: ['1.20.3', '1.21.6', '1.22.4', '1.23.5', '1.24.4', '1.25.2', '1.26.4', '2.0.0']
62+
numpy-version: ['1.20.3', '1.21.6', '1.22.4', '1.23.5', '1.24.4', '1.25.2', '1.26.4']
6363
exclude:
6464
- python-version: '3.10'
6565
numpy-version: '1.20.3'
@@ -107,38 +107,38 @@ jobs:
107107
run: |
108108
pytest --pyargs ufunclab
109109
110-
# main-numpy:
111-
# strategy:
112-
# matrix:
113-
# python-version: ['3.10', '3.11', '3.12']
114-
# os: [ubuntu-latest]
115-
116-
# runs-on: ${{ matrix.os }}
117-
118-
# steps:
119-
# - uses: actions/checkout@v4
120-
# - name: Set up Python
121-
# uses: actions/setup-python@v4
122-
# with:
123-
# python-version: ${{ matrix.python-version }}
124-
# - name: Install dependencies
125-
# run: |
126-
# sudo apt-get install libopenblas-dev
127-
# python -m pip install --upgrade pip wheel
128-
# python -m pip install --upgrade setuptools==59.2.0
129-
# python -m pip install ninja meson-python toml pytest
130-
# pushd .
131-
# cd ..
132-
# git clone --shallow-submodules --recurse-submodules https://github.com/numpy/numpy.git
133-
# cd numpy
134-
# python -m pip install .
135-
# popd
136-
# - name: Install ufunclab
137-
# run: |
138-
# python -m pip install --no-build-isolation .
139-
# - name: Test with pytest
140-
# run: |
141-
# pytest --pyargs ufunclab
110+
main-numpy:
111+
strategy:
112+
matrix:
113+
python-version: ['3.10', '3.11', '3.12']
114+
os: [ubuntu-latest]
115+
116+
runs-on: ${{ matrix.os }}
117+
118+
steps:
119+
- uses: actions/checkout@v4
120+
- name: Set up Python
121+
uses: actions/setup-python@v4
122+
with:
123+
python-version: ${{ matrix.python-version }}
124+
- name: Install dependencies
125+
run: |
126+
sudo apt-get install libopenblas-dev
127+
python -m pip install --upgrade pip wheel
128+
python -m pip install --upgrade setuptools==59.2.0
129+
python -m pip install ninja meson-python toml pytest
130+
pushd .
131+
cd ..
132+
git clone --shallow-submodules --recurse-submodules https://github.com/numpy/numpy.git
133+
cd numpy
134+
python -m pip install .
135+
popd
136+
- name: Install ufunclab
137+
run: |
138+
python -m pip install --no-build-isolation .
139+
- name: Test with pytest
140+
run: |
141+
pytest --pyargs ufunclab
142142
143143
windows-msvc:
144144

README.md

+34-5
Original file line numberDiff line numberDiff line change
@@ -993,11 +993,11 @@ of a NumPy array, but when the input is signed integers, the output
993993
is an unsigned integer with the same bit width.
994994

995995
The function handles the standard integer and floating point types,
996-
and object arrays. The function does not accept complex arrays. Also,
997-
the function does not implement any special handling of `nan`, so the
998-
behavior of this function with arrays containing `nan` is undefined
999-
(i.e. it might not do what you want, and the behavior might change in
1000-
the next update of the software).
996+
`datetime64`, `timedelta64`, and object arrays. The function does not
997+
accept complex arrays. Also, the function does not implement any special
998+
handling of `nan`, so the behavior of this function with arrays containing
999+
`nan` is undefined (i.e. it might not do what you want, and the behavior
1000+
might change in the next update of the software).
10011001

10021002
```
10031003
>>> x = np.array([85, 125, 0, -75, -50], dtype=np.int8)
@@ -1033,6 +1033,35 @@ array([Fraction(59, 21), Fraction(8, 9)], dtype=object)
10331033
10341034
```
10351035

1036+
`dates` is an array of `datetime64`.
1037+
1038+
```
1039+
>>> dates = np.array([np.datetime64('2015-11-02T12:34:50'),
1040+
... np.datetime64('2016-03-01T16:00:00'),
1041+
... np.datetime64('2015-07-02T21:20:19'),
1042+
... np.datetime64('2016-05-01T19:25:00')])
1043+
1044+
>>> dates
1045+
array(['2015-11-02T12:34:50', '2016-03-01T16:00:00',
1046+
'2015-07-02T21:20:19', '2016-05-01T19:25:00'],
1047+
dtype='datetime64[s]')
1048+
>>> timespan = peaktopeak(dates)
1049+
>>> timespan
1050+
numpy.timedelta64(26258681,'s')
1051+
>>> timespan / np.timedelta64(1, 'D') # Convert to number of days.
1052+
303.9199189814815
1053+
```
1054+
1055+
Casting works when the `out` argument is an array with dtype `timedelta64`.
1056+
For example,
1057+
1058+
```
1059+
>>> out = np.empty((), dtype='timedelta64[D]')
1060+
>>> peaktopeak(dates, out=out)
1061+
array(303, dtype='timedelta64[D]')
1062+
1063+
```
1064+
10361065

10371066
#### `all_same`
10381067

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ requires = [
88

99
[project]
1010
name = 'ufunclab'
11-
version = '0.0.8.dev10'
11+
version = '0.0.8.dev9'
1212
description = 'NumPy ufuncs and utilities.'
1313
readme = 'README.md'
1414
requires-python = '>=3.9'

src/peaktopeak/peaktopeak_gufunc.c.src

+5-16
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,6 @@ peaktopeak_@typename@_loop(char **args, const npy_intp *dimensions,
132132
// typical use-cases for these calculations do not encounter this situation.
133133
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
134134

135-
#ifdef UNDEFINED
136-
137-
Handling of datetime64 and timedelta64 is disabled. This code needs to
138-
be updated for NumPy 2.0
139-
140135
static void peaktopeak_int64_signed_loop(char **args, const npy_intp *dimensions,
141136
const npy_intp* steps, void* data)
142137
{
@@ -176,8 +171,6 @@ static void peaktopeak_int64_signed_loop(char **args, const npy_intp *dimensions
176171
}
177172
}
178173

179-
#endif
180-
181174
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
182175
// ufunc inner loop for object arrays.
183176
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -259,8 +252,8 @@ static char peaktopeak_typecodes[] = {
259252
NPY_FLOAT, NPY_FLOAT,
260253
NPY_DOUBLE, NPY_DOUBLE,
261254
NPY_LONGDOUBLE, NPY_LONGDOUBLE,
262-
// NPY_DATETIME, NPY_TIMEDELTA,
263-
// NPY_TIMEDELTA, NPY_TIMEDELTA,
255+
NPY_DATETIME, NPY_TIMEDELTA,
256+
NPY_TIMEDELTA, NPY_TIMEDELTA,
264257
NPY_OBJECT, NPY_OBJECT
265258
};
266259

@@ -276,16 +269,14 @@ static PyUFuncGenericFunction peaktopeak_funcs[] = {
276269
(PyUFuncGenericFunction) &peaktopeak_float_loop,
277270
(PyUFuncGenericFunction) &peaktopeak_double_loop,
278271
(PyUFuncGenericFunction) &peaktopeak_longdouble_loop,
279-
// (PyUFuncGenericFunction) &peaktopeak_int64_signed_loop,
280-
// (PyUFuncGenericFunction) &peaktopeak_int64_signed_loop,
272+
(PyUFuncGenericFunction) &peaktopeak_int64_signed_loop,
273+
(PyUFuncGenericFunction) &peaktopeak_int64_signed_loop,
281274
(PyUFuncGenericFunction) &peaktopeak_object_loop
282275
};
283276

284277
#define PEAKTOPEAK_NTYPES (sizeof(peaktopeak_funcs)/sizeof(peaktopeak_funcs[0]))
285278
static void *peaktopeak_data[PEAKTOPEAK_NTYPES];
286279

287-
#ifdef UNDEFINED
288-
289280
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
290281
// peaktopeak type resolver
291282
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -419,8 +410,6 @@ PeakToPeakTypeResolver(PyUFuncObject *ufunc,
419410
return 0;
420411
}
421412

422-
#endif
423-
424413
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
425414
// Python extension module definitions.
426415
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -477,7 +466,7 @@ PyMODINIT_FUNC PyInit__peaktopeak(void)
477466
Py_DECREF(module);
478467
return NULL;
479468
}
480-
// peaktopeak_gufunc->type_resolver = PeakToPeakTypeResolver;
469+
peaktopeak_gufunc->type_resolver = PeakToPeakTypeResolver;
481470

482471
status = PyModule_AddObject(module, "peaktopeak", (PyObject *) peaktopeak_gufunc);
483472
if (status == -1) {

src/searchsorted/searchsorted_gufunc.c.src

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ SearchSortedTypeResolver(PyUFuncObject *ufunc,
9090
*/
9191
type_num1 = PyArray_DESCR(operands[0])->type_num;
9292
type_num2 = PyArray_DESCR(operands[1])->type_num;
93-
if (type_num1 >= NPY_NTYPES_LEGACY || type_num2 >= NPY_NTYPES_LEGACY ||
93+
if (type_num1 >= NPY_NTYPES || type_num2 >= NPY_NTYPES ||
9494
type_num1 == NPY_OBJECT || type_num2 == NPY_OBJECT) {
9595
return PyUFunc_DefaultTypeResolver(ufunc, casting, operands,
9696
type_tup, out_dtypes);

ufunclab/tests/test_peaktopeak.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,11 @@ def test_fractions_2d():
6464
assert_array_equal(p1, [Fraction(23, 9), Fraction(0)])
6565

6666

67-
# Removed until datetime64 and timedelta64 handling is restored
68-
# in ufunclab.peaktopeak.
69-
#
70-
# def test_dates():
71-
# dates = np.array([np.datetime64('2015-11-02T12:34:50'),
72-
# np.datetime64('2015-11-02T10:00:00'),
73-
# np.datetime64('2015-11-02T21:20:19'),
74-
# np.datetime64('2015-11-02T19:25:00')])
75-
# timespan = peaktopeak(dates)
76-
# assert_equal(timespan.dtype, np.dtype('m8[s]'))
77-
# assert_equal(timespan, np.timedelta64(40819, 's'))
67+
def test_dates():
68+
dates = np.array([np.datetime64('2015-11-02T12:34:50'),
69+
np.datetime64('2015-11-02T10:00:00'),
70+
np.datetime64('2015-11-02T21:20:19'),
71+
np.datetime64('2015-11-02T19:25:00')])
72+
timespan = peaktopeak(dates)
73+
assert_equal(timespan.dtype, np.dtype('m8[s]'))
74+
assert_equal(timespan, np.timedelta64(40819, 's'))

0 commit comments

Comments
 (0)