Skip to content

Some functions in Agg wrapper don't play nice with numpy dtypes #95

@tonysyu

Description

@tonysyu

I noticed this issue with GraphicsContextArray.clip_to_rect, but I imagine this is an issue in a few other agg functions.

This issue pops up when running one of the Chaco examples:

https://github.com/enthought/chaco/blob/master/examples/user_guide/grid_plot_container.py

The problem in the example is that the height is being set to an int, which gets converted to a numpy int at some point. A python int seems to cast correctly, but numpy ints don't:

import numpy as np
from kiva.agg import GraphicsContextArray


def python_ints(values):
    return [int(a) for a in values]

def python_floats(values):
    return [float(a) for a in values]


def test_clip_to_rect_dtypes():

    gc = GraphicsContextArray((3, 3))
    rect = np.zeros(4)

    convert_funcs = [
        python_ints,
        python_floats,
        np.float64,
        np.float32,
        np.int64,
        np.int32,
        np.uint8,
    ]

    with gc:
        for convert in convert_funcs:
            try:
                gc.clip_to_rect(*convert(rect))
            except Exception as error:
                print convert
                print error

if __name__ == '__main__':
    test_clip_to_rect_dtypes()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions