Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d4b45d0

Browse filesBrowse files
committed
Deprecate passing floats to RendererAgg.draw_text_image
These were silently truncated to int anyway, so we should make the types explicit.
1 parent 6e60725 commit d4b45d0
Copy full SHA for d4b45d0

File tree

Expand file treeCollapse file tree

2 files changed

+33
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+33
-2
lines changed
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Passing floating-point values to ``RendererAgg.draw_text_image``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
Any floating-point values passed to the *x* and *y* parameters were truncated to integers
5+
silently. This behaviour is now deprecated, and only `int` values should be used.

‎src/_backend_agg_wrapper.cpp

Copy file name to clipboardExpand all lines: src/_backend_agg_wrapper.cpp
+28-2Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,37 @@ PyRendererAgg_draw_path(RendererAgg *self,
5858
static void
5959
PyRendererAgg_draw_text_image(RendererAgg *self,
6060
py::array_t<agg::int8u, py::array::c_style | py::array::forcecast> image_obj,
61-
double x,
62-
double y,
61+
std::variant<double, int> vx,
62+
std::variant<double, int> vy,
6363
double angle,
6464
GCAgg &gc)
6565
{
66+
int x, y;
67+
68+
if (auto value = std::get_if<double>(&vx)) {
69+
auto api = py::module_::import("matplotlib._api");
70+
auto warn = api.attr("warn_deprecated");
71+
warn("since"_a="3.10", "name"_a="x", "obj_type"_a="parameter as float",
72+
"alternative"_a="int(x)");
73+
x = static_cast<int>(*value);
74+
} else if (auto value = std::get_if<int>(&vx)) {
75+
x = *value;
76+
} else {
77+
throw std::runtime_error("Should not happen");
78+
}
79+
80+
if (auto value = std::get_if<double>(&vy)) {
81+
auto api = py::module_::import("matplotlib._api");
82+
auto warn = api.attr("warn_deprecated");
83+
warn("since"_a="3.10", "name"_a="y", "obj_type"_a="parameter as float",
84+
"alternative"_a="int(y)");
85+
y = static_cast<int>(*value);
86+
} else if (auto value = std::get_if<int>(&vy)) {
87+
y = *value;
88+
} else {
89+
throw std::runtime_error("Should not happen");
90+
}
91+
6692
// TODO: This really shouldn't be mutable, but Agg's renderer buffers aren't const.
6793
auto image = image_obj.mutable_unchecked<2>();
6894

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.