Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0f4a68d

Browse files
committed
Merge pull request #3547 from jkseppan/numpy-deprecation
Conflicts: src/_path.cpp Conflicted with bug fix for picking zero length path collection 5e2b03c PR #3592
2 parents 7f71233 + b279c15 commit 0f4a68d

15 files changed

+448
-396
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ env:
66
- secure: E7OCdqhZ+PlwJcn+Hd6ns9TDJgEUXiUNEI0wu7xjxB2vBRRIKtZMbuaZjd+iKDqCKuVOJKu0ClBUYxmgmpLicTwi34CfTUYt6D4uhrU+8hBBOn1iiK51cl/aBvlUUrqaRLVhukNEBGZcyqAjXSA/Qsnp2iELEmAfOUa92ZYo1sk=
77
- BUILD_DOCS=false
88
- TEST_ARGS=--no-pep8
9+
- NUMPY=numpy
910

1011
language: python
1112

1213
matrix:
1314
include:
1415
- python: 2.6
16+
env: NUMPY=numpy==1.6
1517
- python: 2.7
1618
- python: 3.3
1719
- python: 3.4
@@ -21,7 +23,7 @@ matrix:
2123
env: BUILD_DOCS=true
2224

2325
install:
24-
- pip install -q --use-mirrors nose python-dateutil numpy pep8 pyparsing pillow
26+
- pip install -q --use-mirrors nose python-dateutil $NUMPY pep8 pyparsing pillow
2527
- sudo apt-get update && sudo apt-get -qq install inkscape libav-tools
2628
# We use --no-install-recommends to avoid pulling in additional large latex docs that we don't need
2729
- if [[ $BUILD_DOCS == true ]]; then sudo apt-get install -qq --no-install-recommends dvipng texlive-latex-base texlive-latex-extra texlive-fonts-recommended graphviz; fi

lib/matplotlib/delaunay/_delaunay.cpp

Lines changed: 99 additions & 78 deletions
Large diffs are not rendered by default.

lib/matplotlib/tri/_tri.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ void Triangulation::calculate_edges()
328328

329329
// Convert to python _edges array.
330330
npy_intp dims[2] = {static_cast<npy_intp>(edge_set.size()), 2};
331-
_edges = (PyArrayObject*)PyArray_SimpleNew(2, dims, PyArray_INT);
331+
_edges = (PyArrayObject*)PyArray_SimpleNew(2, dims, NPY_INT);
332332
int* edges_ptr = (int*)PyArray_DATA(_edges);
333333
for (EdgeSet::const_iterator it = edge_set.begin(); it != edge_set.end(); ++it) {
334334
*edges_ptr++ = it->start;
@@ -343,7 +343,7 @@ void Triangulation::calculate_neighbors()
343343

344344
// Create _neighbors array with shape (ntri,3) and initialise all to -1.
345345
npy_intp dims[2] = {_ntri,3};
346-
_neighbors = (PyArrayObject*)PyArray_SimpleNew(2, dims, PyArray_INT);
346+
_neighbors = (PyArrayObject*)PyArray_SimpleNew(2, dims, NPY_INT);
347347
int* neighbors_ptr = (int*)PyArray_DATA(_neighbors);
348348
std::fill(neighbors_ptr, neighbors_ptr + 3*_ntri, -1);
349349

@@ -386,7 +386,7 @@ Py::Object Triangulation::calculate_plane_coefficients(const Py::Tuple &args)
386386
args.verify_length(1);
387387

388388
PyArrayObject* z = (PyArrayObject*)PyArray_ContiguousFromObject(
389-
args[0].ptr(), PyArray_DOUBLE, 1, 1);
389+
args[0].ptr(), NPY_DOUBLE, 1, 1);
390390
if (z == 0 || PyArray_DIM(z,0) != PyArray_DIM(_x,0)) {
391391
Py_XDECREF(z);
392392
throw Py::ValueError(
@@ -401,7 +401,7 @@ Py::Object Triangulation::calculate_plane_coefficients(const Py::Tuple &args)
401401

402402
npy_intp dims[2] = {_ntri, 3};
403403
planes_array = (PyArrayObject*)PyArray_SimpleNew(2, dims,
404-
PyArray_DOUBLE);
404+
NPY_DOUBLE);
405405
double* planes = (double*)PyArray_DATA(planes_array);
406406
const int* tris = get_triangles_ptr();
407407
const double* xs = (const double*)PyArray_DATA(_x);
@@ -624,7 +624,7 @@ Py::Object Triangulation::set_mask(const Py::Tuple &args)
624624
if (args[0] != Py::None())
625625
{
626626
_mask = (PyArrayObject*)PyArray_ContiguousFromObject(
627-
args[0].ptr(), PyArray_BOOL, 1, 1);
627+
args[0].ptr(), NPY_BOOL, 1, 1);
628628
if (_mask == 0 || PyArray_DIM(_mask,0) != PyArray_DIM(_triangles,0)) {
629629
Py_XDECREF(_mask);
630630
throw Py::ValueError(
@@ -712,7 +712,7 @@ Py::Object TriContourGenerator::contour_to_segs(const Contour& contour)
712712
const ContourLine& line = contour[i];
713713
npy_intp dims[2] = {static_cast<npy_intp>(line.size()),2};
714714
PyArrayObject* py_line = (PyArrayObject*)PyArray_SimpleNew(
715-
2, dims, PyArray_DOUBLE);
715+
2, dims, NPY_DOUBLE);
716716
double* p = (double*)PyArray_DATA(py_line);
717717
for (ContourLine::const_iterator it = line.begin(); it != line.end(); ++it) {
718718
*p++ = it->x;
@@ -736,13 +736,13 @@ Py::Object TriContourGenerator::contour_to_segs_and_kinds(const Contour& contour
736736
// Create segs array for point coordinates.
737737
npy_intp segs_dims[2] = {n_points, 2};
738738
PyArrayObject* segs = (PyArrayObject*)PyArray_SimpleNew(
739-
2, segs_dims, PyArray_DOUBLE);
739+
2, segs_dims, NPY_DOUBLE);
740740
double* segs_ptr = (double*)PyArray_DATA(segs);
741741

742742
// Create kinds array for code types.
743743
npy_intp kinds_dims[1] = {n_points};
744744
PyArrayObject* kinds = (PyArrayObject*)PyArray_SimpleNew(
745-
1, kinds_dims, PyArray_UBYTE);
745+
1, kinds_dims, NPY_UBYTE);
746746
unsigned char* kinds_ptr = (unsigned char*)PyArray_DATA(kinds);
747747

748748
for (line = contour.begin(); line != contour.end(); ++line) {
@@ -1367,9 +1367,9 @@ TrapezoidMapTriFinder::find_many(const Py::Tuple& args)
13671367

13681368
// Check input arguments.
13691369
PyArrayObject* x = (PyArrayObject*)PyArray_ContiguousFromObject(
1370-
args[0].ptr(), PyArray_DOUBLE, 0, 0);
1370+
args[0].ptr(), NPY_DOUBLE, 0, 0);
13711371
PyArrayObject* y = (PyArrayObject*)PyArray_ContiguousFromObject(
1372-
args[1].ptr(), PyArray_DOUBLE, 0, 0);
1372+
args[1].ptr(), NPY_DOUBLE, 0, 0);
13731373
bool ok = (x != 0 && y != 0 && PyArray_NDIM(x) == PyArray_NDIM(y));
13741374
int ndim = x == 0 ? 0 : PyArray_NDIM(x);
13751375
for (int i = 0; ok && i < ndim; ++i)
@@ -1383,7 +1383,7 @@ TrapezoidMapTriFinder::find_many(const Py::Tuple& args)
13831383

13841384
// Create integer array to return.
13851385
PyArrayObject* tri = (PyArrayObject*)PyArray_SimpleNew(
1386-
ndim, PyArray_DIMS(x), PyArray_INT);
1386+
ndim, PyArray_DIMS(x), NPY_INT);
13871387

13881388
// Fill returned array.
13891389
double* x_ptr = (double*)PyArray_DATA(x);
@@ -2234,9 +2234,9 @@ Py::Object TriModule::new_triangulation(const Py::Tuple &args)
22342234

22352235
// x and y.
22362236
PyArrayObject* x = (PyArrayObject*)PyArray_ContiguousFromObject(
2237-
args[0].ptr(), PyArray_DOUBLE, 1, 1);
2237+
args[0].ptr(), NPY_DOUBLE, 1, 1);
22382238
PyArrayObject* y = (PyArrayObject*)PyArray_ContiguousFromObject(
2239-
args[1].ptr(), PyArray_DOUBLE, 1, 1);
2239+
args[1].ptr(), NPY_DOUBLE, 1, 1);
22402240
if (x == 0 || y == 0 || PyArray_DIM(x,0) != PyArray_DIM(y,0)) {
22412241
Py_XDECREF(x);
22422242
Py_XDECREF(y);
@@ -2245,7 +2245,7 @@ Py::Object TriModule::new_triangulation(const Py::Tuple &args)
22452245

22462246
// triangles.
22472247
PyArrayObject* triangles = (PyArrayObject*)PyArray_ContiguousFromObject(
2248-
args[2].ptr(), PyArray_INT, 2, 2);
2248+
args[2].ptr(), NPY_INT, 2, 2);
22492249
if (triangles == 0 || PyArray_DIM(triangles,1) != 3) {
22502250
Py_XDECREF(x);
22512251
Py_XDECREF(y);
@@ -2258,7 +2258,7 @@ Py::Object TriModule::new_triangulation(const Py::Tuple &args)
22582258
if (args[3].ptr() != 0 && args[3] != Py::None())
22592259
{
22602260
mask = (PyArrayObject*)PyArray_ContiguousFromObject(
2261-
args[3].ptr(), PyArray_BOOL, 1, 1);
2261+
args[3].ptr(), NPY_BOOL, 1, 1);
22622262
if (mask == 0 || PyArray_DIM(mask,0) != PyArray_DIM(triangles,0)) {
22632263
Py_XDECREF(x);
22642264
Py_XDECREF(y);
@@ -2274,7 +2274,7 @@ Py::Object TriModule::new_triangulation(const Py::Tuple &args)
22742274
if (args[4].ptr() != 0 && args[4] != Py::None())
22752275
{
22762276
edges = (PyArrayObject*)PyArray_ContiguousFromObject(
2277-
args[4].ptr(), PyArray_INT, 2, 2);
2277+
args[4].ptr(), NPY_INT, 2, 2);
22782278
if (edges == 0 || PyArray_DIM(edges,1) != 2) {
22792279
Py_XDECREF(x);
22802280
Py_XDECREF(y);
@@ -2290,7 +2290,7 @@ Py::Object TriModule::new_triangulation(const Py::Tuple &args)
22902290
if (args[5].ptr() != 0 && args[5] != Py::None())
22912291
{
22922292
neighbors = (PyArrayObject*)PyArray_ContiguousFromObject(
2293-
args[5].ptr(), PyArray_INT, 2, 2);
2293+
args[5].ptr(), NPY_INT, 2, 2);
22942294
if (neighbors == 0 ||
22952295
PyArray_DIM(neighbors,0) != PyArray_DIM(triangles,0) ||
22962296
PyArray_DIM(neighbors,1) != PyArray_DIM(triangles,1)) {
@@ -2318,7 +2318,7 @@ Py::Object TriModule::new_tricontourgenerator(const Py::Tuple &args)
23182318
throw Py::ValueError("Expecting a C++ Triangulation object");
23192319

23202320
PyArrayObject* z = (PyArrayObject*)PyArray_ContiguousFromObject(
2321-
args[1].ptr(), PyArray_DOUBLE, 1, 1);
2321+
args[1].ptr(), NPY_DOUBLE, 1, 1);
23222322
if (z == 0 ||
23232323
PyArray_DIM(z,0) != ((Triangulation*)tri.ptr())->get_npoints()) {
23242324
Py_XDECREF(z);

setupext.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,9 @@ def add_flags(self, ext):
830830
ext.define_macros.append(('PY_ARRAY_UNIQUE_SYMBOL', array_api_name))
831831
ext.add_hook('include_dirs', self.include_dirs_hook)
832832

833+
ext.define_macros.append(('NPY_NO_DEPRECATED_API',
834+
'NPY_1_7_API_VERSION'))
835+
833836
def get_setup_requires(self):
834837
return ['numpy>=1.6']
835838

src/_backend_agg.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -947,16 +947,16 @@ RendererAgg::draw_text_image(const Py::Tuple& args)
947947
if (PyArray_Check(image_obj.ptr()))
948948
{
949949
PyObject* image_array = PyArray_FromObject(
950-
image_obj.ptr(), PyArray_UBYTE, 2, 2);
950+
image_obj.ptr(), NPY_UBYTE, 2, 2);
951951
if (!image_array)
952952
{
953953
throw Py::ValueError(
954954
"First argument to draw_text_image must be a FT2Font.Image object or a Nx2 uint8 numpy array.");
955955
}
956956
image_obj = Py::Object(image_array, true);
957-
buffer = (unsigned char *)PyArray_DATA(image_array);
958-
width = PyArray_DIM(image_array, 1);
959-
height = PyArray_DIM(image_array, 0);
957+
buffer = (unsigned char *)PyArray_DATA((PyArrayObject*)image_array);
958+
width = PyArray_DIM((PyArrayObject*)image_array, 1);
959+
height = PyArray_DIM((PyArrayObject*)image_array, 0);
960960
}
961961
else
962962
{
@@ -1500,7 +1500,7 @@ RendererAgg::_draw_path_collection_generic
15001500
typedef agg::conv_curve<clipped_t> curve_t;
15011501

15021502
PyArrayObject* offsets = (PyArrayObject*)PyArray_FromObject
1503-
(offsets_obj.ptr(), PyArray_DOUBLE, 0, 2);
1503+
(offsets_obj.ptr(), NPY_DOUBLE, 0, 2);
15041504
if (!offsets ||
15051505
(PyArray_NDIM(offsets) == 2 && PyArray_DIM(offsets, 1) != 2) ||
15061506
(PyArray_NDIM(offsets) == 1 && PyArray_DIM(offsets, 0) != 0))
@@ -1511,7 +1511,7 @@ RendererAgg::_draw_path_collection_generic
15111511
Py::Object offsets_arr_obj((PyObject*)offsets, true);
15121512

15131513
PyArrayObject* facecolors = (PyArrayObject*)PyArray_FromObject
1514-
(facecolors_obj.ptr(), PyArray_DOUBLE, 1, 2);
1514+
(facecolors_obj.ptr(), NPY_DOUBLE, 1, 2);
15151515
if (!facecolors ||
15161516
(PyArray_NDIM(facecolors) == 1 && PyArray_DIM(facecolors, 0) != 0) ||
15171517
(PyArray_NDIM(facecolors) == 2 && PyArray_DIM(facecolors, 1) != 4))
@@ -1522,7 +1522,7 @@ RendererAgg::_draw_path_collection_generic
15221522
Py::Object facecolors_arr_obj((PyObject*)facecolors, true);
15231523

15241524
PyArrayObject* edgecolors = (PyArrayObject*)PyArray_FromObject
1525-
(edgecolors_obj.ptr(), PyArray_DOUBLE, 1, 2);
1525+
(edgecolors_obj.ptr(), NPY_DOUBLE, 1, 2);
15261526
if (!edgecolors ||
15271527
(PyArray_NDIM(edgecolors) == 1 && PyArray_DIM(edgecolors, 0) != 0) ||
15281528
(PyArray_NDIM(edgecolors) == 2 && PyArray_DIM(edgecolors, 1) != 4))
@@ -1533,7 +1533,7 @@ RendererAgg::_draw_path_collection_generic
15331533
Py::Object edgecolors_arr_obj((PyObject*)edgecolors, true);
15341534

15351535
PyArrayObject* transforms_arr = (PyArrayObject*)PyArray_FromObject
1536-
(transforms_obj.ptr(), PyArray_DOUBLE, 1, 3);
1536+
(transforms_obj.ptr(), NPY_DOUBLE, 1, 3);
15371537
if (!transforms_arr ||
15381538
(PyArray_NDIM(transforms_arr) == 1 && PyArray_DIM(transforms_arr, 0) != 0) ||
15391539
(PyArray_NDIM(transforms_arr) == 2) ||
@@ -1546,11 +1546,11 @@ RendererAgg::_draw_path_collection_generic
15461546
}
15471547

15481548
size_t Npaths = path_generator.num_paths();
1549-
size_t Noffsets = offsets->dimensions[0];
1549+
size_t Noffsets = PyArray_DIM(offsets, 0);
15501550
size_t N = std::max(Npaths, Noffsets);
1551-
size_t Ntransforms = transforms_arr->dimensions[0];
1552-
size_t Nfacecolors = facecolors->dimensions[0];
1553-
size_t Nedgecolors = edgecolors->dimensions[0];
1551+
size_t Ntransforms = PyArray_DIM(transforms_arr, 0);
1552+
size_t Nfacecolors = PyArray_DIM(facecolors, 0);
1553+
size_t Nedgecolors = PyArray_DIM(edgecolors, 0);
15541554
size_t Nlinewidths = linewidths.length();
15551555
size_t Nlinestyles = std::min(linestyles_obj.length(), N);
15561556
size_t Naa = antialiaseds.length();
@@ -1867,7 +1867,7 @@ class QuadMeshGenerator
18671867
{
18681868
PyArrayObject* coordinates_array = \
18691869
(PyArrayObject*)PyArray_ContiguousFromObject(
1870-
coordinates, PyArray_DOUBLE, 3, 3);
1870+
coordinates, NPY_DOUBLE, 3, 3);
18711871

18721872
if (!coordinates_array)
18731873
{
@@ -1931,7 +1931,7 @@ RendererAgg::draw_quad_mesh(const Py::Tuple& args)
19311931
else
19321932
{
19331933
npy_intp dims[] = { 0, 0 };
1934-
edgecolors_obj = PyArray_SimpleNew(1, dims, PyArray_DOUBLE);
1934+
edgecolors_obj = PyArray_SimpleNew(1, dims, NPY_DOUBLE);
19351935
}
19361936
}
19371937

@@ -2040,7 +2040,7 @@ RendererAgg::draw_gouraud_triangle(const Py::Tuple& args)
20402040
bool has_clippath = render_clippath(gc.clippath, gc.clippath_trans);
20412041

20422042
PyArrayObject* points = (PyArrayObject*)PyArray_ContiguousFromAny
2043-
(points_obj.ptr(), PyArray_DOUBLE, 2, 2);
2043+
(points_obj.ptr(), NPY_DOUBLE, 2, 2);
20442044
if (!points ||
20452045
PyArray_DIM(points, 0) != 3 || PyArray_DIM(points, 1) != 2)
20462046
{
@@ -2050,7 +2050,7 @@ RendererAgg::draw_gouraud_triangle(const Py::Tuple& args)
20502050
points_obj = Py::Object((PyObject*)points, true);
20512051

20522052
PyArrayObject* colors = (PyArrayObject*)PyArray_ContiguousFromAny
2053-
(colors_obj.ptr(), PyArray_DOUBLE, 2, 2);
2053+
(colors_obj.ptr(), NPY_DOUBLE, 2, 2);
20542054
if (!colors ||
20552055
PyArray_DIM(colors, 0) != 3 || PyArray_DIM(colors, 1) != 4)
20562056
{
@@ -2089,7 +2089,7 @@ RendererAgg::draw_gouraud_triangles(const Py::Tuple& args)
20892089
bool has_clippath = render_clippath(gc.clippath, gc.clippath_trans);
20902090

20912091
PyArrayObject* points = (PyArrayObject*)PyArray_FromObject
2092-
(points_obj.ptr(), PyArray_DOUBLE, 3, 3);
2092+
(points_obj.ptr(), NPY_DOUBLE, 3, 3);
20932093
if (!points ||
20942094
PyArray_DIM(points, 1) != 3 || PyArray_DIM(points, 2) != 2)
20952095
{
@@ -2099,7 +2099,7 @@ RendererAgg::draw_gouraud_triangles(const Py::Tuple& args)
20992099
points_obj = Py::Object((PyObject*)points, true);
21002100

21012101
PyArrayObject* colors = (PyArrayObject*)PyArray_FromObject
2102-
(colors_obj.ptr(), PyArray_DOUBLE, 3, 3);
2102+
(colors_obj.ptr(), NPY_DOUBLE, 3, 3);
21032103
if (!colors ||
21042104
PyArray_DIM(colors, 1) != 3 || PyArray_DIM(colors, 2) != 4)
21052105
{

src/_backend_gdk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pixbuf_get_pixels_array(PyObject *self, PyObject *args)
3535
if (gdk_pixbuf_get_has_alpha(gdk_pixbuf))
3636
dims[2] = 4;
3737

38-
array = (PyArrayObject *)PyArray_SimpleNewFromData(3, dims, PyArray_UBYTE,
38+
array = (PyArrayObject *)PyArray_SimpleNewFromData(3, dims, NPY_UBYTE,
3939
(char *)gdk_pixbuf_get_pixels(gdk_pixbuf));
4040
if (array == NULL)
4141
return NULL;

0 commit comments

Comments
 (0)