Skip to content

Commit 2c54949

Browse files
committed
Remove use of deprected numpy API
1 parent a256b9a commit 2c54949

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

pyhdf/hdfext.i

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ extern void _HEprint(void);
205205
%{
206206
#include "hdfi.h" /* declares int32, float32, etc */
207207

208+
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
208209
#include "numpy/ndarraytypes.h"
209210
#include "numpy/ndarrayobject.h"
210211

@@ -246,7 +247,7 @@ static int HDFtoNumericType(int hdf) {
246247
#ifndef NOUINT
247248
case DFNT_UINT32 : num = NPY_UINT; break;
248249
#endif
249-
case DFNT_CHAR8 : num = NPY_CHAR; break;
250+
case DFNT_CHAR8 : num = NPY_STRING; break;
250251
case DFNT_UCHAR8 : num = NPY_UBYTE; break;
251252
default:
252253
num = -1;
@@ -337,7 +338,7 @@ static PyObject * _SDreaddata_0(int32 sds_id, int32 data_type,
337338
* Load it from the SDS.
338339
*/
339340
status = SDreaddata(sds_id, startArr, strideArr, edgesArr,
340-
array -> data);
341+
PyArray_DATA(array));
341342
if (status < 0) {
342343
PyErr_SetString(PyExc_ValueError, "SDreaddata failure");
343344
Py_DECREF(array); /* Free array */
@@ -354,28 +355,28 @@ static PyObject * _SDreaddata_0(int32 sds_id, int32 data_type,
354355
return (PyObject *) array;
355356
switch (num_type) {
356357
case NPY_FLOAT:
357-
f32 = *(float *) array->data;
358+
f32 = *(float *) PyArray_DATA(array);
358359
o = PyFloat_FromDouble((double) f32);
359360
break;
360361
case NPY_DOUBLE:
361-
f64 = *(double *) array->data;
362+
f64 = *(double *) PyArray_DATA(array);
362363
o = PyFloat_FromDouble(f64);
363364
break;
364-
case NPY_CHAR:
365+
case NPY_STRING:
365366
case NPY_BYTE:
366-
i32 = *(char *) array->data;
367+
i32 = *(char *) PyArray_DATA(array);
367368
o = PyInt_FromLong((long) i32);
368369
break;
369370
case NPY_UBYTE:
370-
i32 = *(unsigned char *) array->data;
371+
i32 = *(unsigned char *) PyArray_DATA(array);
371372
o = PyInt_FromLong((long) i32);
372373
break;
373374
case NPY_SHORT:
374-
i32 = *(short *) array->data;
375+
i32 = *(short *) PyArray_DATA(array);
375376
o = PyInt_FromLong((long) i32);
376377
break;
377378
case NPY_INT:
378-
i32 = *(int *) array->data;
379+
i32 = *(int *) PyArray_DATA(array);
379380
o = PyInt_FromLong((long) i32);
380381
break;
381382
}
@@ -446,7 +447,7 @@ static PyObject * _SDwritedata_0(int32 sds_id, int32 data_type,
446447
* Store in the SDS.
447448
*/
448449
status = SDwritedata(sds_id, startArr, strideArr, edgesArr,
449-
array -> data);
450+
PyArray_DATA(array));
450451
Py_DECREF(array); /* Free array */
451452
if (status < 0) {
452453
PyErr_SetString(PyExc_ValueError, "SDwritedata failure");

pyhdf/hdfext_wrap.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3844,6 +3844,7 @@ void _HEprint(void) {
38443844

38453845
#include "hdfi.h" /* declares int32, float32, etc */
38463846

3847+
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
38473848
#include "numpy/ndarraytypes.h"
38483849
#include "numpy/ndarrayobject.h"
38493850

@@ -3885,7 +3886,7 @@ static int HDFtoNumericType(int hdf) {
38853886
#ifndef NOUINT
38863887
case DFNT_UINT32 : num = NPY_UINT; break;
38873888
#endif
3888-
case DFNT_CHAR8 : num = NPY_CHAR; break;
3889+
case DFNT_CHAR8 : num = NPY_STRING; break;
38893890
case DFNT_UCHAR8 : num = NPY_UBYTE; break;
38903891
default:
38913892
num = -1;
@@ -3976,7 +3977,7 @@ static PyObject * _SDreaddata_0(int32 sds_id, int32 data_type,
39763977
* Load it from the SDS.
39773978
*/
39783979
status = SDreaddata(sds_id, startArr, strideArr, edgesArr,
3979-
array -> data);
3980+
PyArray_DATA(array));
39803981
if (status < 0) {
39813982
PyErr_SetString(PyExc_ValueError, "SDreaddata failure");
39823983
Py_DECREF(array); /* Free array */
@@ -3993,28 +3994,28 @@ static PyObject * _SDreaddata_0(int32 sds_id, int32 data_type,
39933994
return (PyObject *) array;
39943995
switch (num_type) {
39953996
case NPY_FLOAT:
3996-
f32 = *(float *) array->data;
3997+
f32 = *(float *) PyArray_DATA(array);
39973998
o = PyFloat_FromDouble((double) f32);
39983999
break;
39994000
case NPY_DOUBLE:
4000-
f64 = *(double *) array->data;
4001+
f64 = *(double *) PyArray_DATA(array);
40014002
o = PyFloat_FromDouble(f64);
40024003
break;
4003-
case NPY_CHAR:
4004+
case NPY_STRING:
40044005
case NPY_BYTE:
4005-
i32 = *(char *) array->data;
4006+
i32 = *(char *) PyArray_DATA(array);
40064007
o = PyInt_FromLong((long) i32);
40074008
break;
40084009
case NPY_UBYTE:
4009-
i32 = *(unsigned char *) array->data;
4010+
i32 = *(unsigned char *) PyArray_DATA(array);
40104011
o = PyInt_FromLong((long) i32);
40114012
break;
40124013
case NPY_SHORT:
4013-
i32 = *(short *) array->data;
4014+
i32 = *(short *) PyArray_DATA(array);
40144015
o = PyInt_FromLong((long) i32);
40154016
break;
40164017
case NPY_INT:
4017-
i32 = *(int *) array->data;
4018+
i32 = *(int *) PyArray_DATA(array);
40184019
o = PyInt_FromLong((long) i32);
40194020
break;
40204021
}
@@ -4085,7 +4086,7 @@ static PyObject * _SDwritedata_0(int32 sds_id, int32 data_type,
40854086
* Store in the SDS.
40864087
*/
40874088
status = SDwritedata(sds_id, startArr, strideArr, edgesArr,
4088-
array -> data);
4089+
PyArray_DATA(array));
40894090
Py_DECREF(array); /* Free array */
40904091
if (status < 0) {
40914092
PyErr_SetString(PyExc_ValueError, "SDwritedata failure");

0 commit comments

Comments
 (0)