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

Skip to content

Commit 709d7e3

Browse files
anntzerchahak13
authored andcommitted
Deprecate BufferRegion.to_string{,_argb}.
These methods are unused; it is better to directly get array views (this saves a copy); and removing them prepares for a possible future where BufferRegions mostly go away and copy_from_bbox/restore_region directly operate on numpy arrays.
1 parent 8014599 commit 709d7e3

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``BufferRegion.to_string`` and ``BufferRegion.to_string_argb``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
... are deprecated. Use ``np.asarray(buffer_region)`` to get an array view on
4+
a buffer region without making a copy; to convert that view from RGBA (the
5+
default) to ARGB, use ``np.take(..., [2, 1, 0, 3], axis=2)``.

src/_backend_agg_wrapper.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ static void PyBufferRegion_dealloc(PyBufferRegion *self)
4646

4747
static PyObject *PyBufferRegion_to_string(PyBufferRegion *self, PyObject *args)
4848
{
49+
char const* msg =
50+
"BufferRegion.to_string is deprecated since Matplotlib 3.7 and will "
51+
"be removed two minor releases later; use np.asarray(region) instead.";
52+
if (PyErr_WarnEx(PyExc_DeprecationWarning, msg, 1)) {
53+
return NULL;
54+
}
4955
return PyBytes_FromStringAndSize((const char *)self->x->get_data(),
5056
self->x->get_height() * self->x->get_stride());
5157
}
@@ -83,6 +89,13 @@ static PyObject *PyBufferRegion_get_extents(PyBufferRegion *self, PyObject *args
8389

8490
static PyObject *PyBufferRegion_to_string_argb(PyBufferRegion *self, PyObject *args)
8591
{
92+
char const* msg =
93+
"BufferRegion.to_string_argb is deprecated since Matplotlib 3.7 and "
94+
"will be removed two minor releases later; use "
95+
"np.take(region, [2, 1, 0, 3], axis=2) instead.";
96+
if (PyErr_WarnEx(PyExc_DeprecationWarning, msg, 1)) {
97+
return NULL;
98+
}
8699
PyObject *bufobj;
87100
uint8_t *buf;
88101

0 commit comments

Comments
 (0)