Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: fix marker size type mismatch error #859

Merged
merged 19 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions chaco/examples/demo/basic/scatter_1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ def _create_plot_component():
alignment="left",
)

plot.plot_1d(
"value",
type="scatter_1d",
orientation="v",
marker="plus",
alignment="left",
marker_size=randint(1,5, numpts)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the correct usage and should fail. You would need to specify a data source for the size values which holds the sizes.

)

plot.plot(
("index", "value"),
type="scatter",
Expand Down
6 changes: 4 additions & 2 deletions chaco/plots/scatterplot_1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# Enthought library imports
from enable.api import black_color_trait, ColorTrait, MarkerTrait
from traits.api import Any, Bool, Callable, Enum, Float, Str
from traits.api import Any, Array, Bool, Callable, Enum, Float, Str, Union

# local imports
from chaco.base_1d_plot import Base1DPlot
Expand All @@ -32,7 +32,9 @@ class ScatterPlot1D(Base1DPlot):
marker = MarkerTrait

# The pixel size of the marker, not including the thickness of the outline.
marker_size = Float(4.0)
marker_size = Union(Float,
Array(dtype=float),
default_value=4.0)
Copy link
Contributor

@corranwebster corranwebster Apr 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is absolutely not correct - Chaco data never comes from hard-coded arrays like this. Most likely this should be a Float or an Instance(AbstractDataSource).


# The CompiledPath to use if **marker** is set to "custom". This attribute
# must be a compiled path for the Kiva context onto which this plot will
Expand Down
134 changes: 134 additions & 0 deletions chaco/tests/test_scatter_1d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# (C) Copyright 2005-2021 Enthought, Inc., Austin, TX
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE.txt and may be redistributed only under
# the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!

"""
Unit tests for scatter_1d function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"""

from numpy import sort
from numpy.random import random, randint, uniform
import unittest
from chaco.api import ArrayPlotData, Plot


class Scatter1DTestCase(unittest.TestCase):
def test_default_marker_size(self):
# Create some data
numpts = 50
x = sort(random(numpts))
y = random(numpts)

# Create a plot data object and give it this data
pd = ArrayPlotData()
pd.set_data("index", x)
pd.set_data("value", y)

# Create the plot
plot = Plot(pd, use_backbuffer=True, auto_grid=False)

plot.plot_1d(
"value",
type="scatter_1d",
orientation="v",
marker="plus",
alignment="left"
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nothing is really being tested here. What do you expect to test? Verify that something is generated without exception? ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is applicable to all the tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, these tests are limited to check for traits mismatch exceptions. Is there other stuffs we want to test?

Copy link
Contributor

@corranwebster corranwebster Apr 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a test of the default marker size, you should somewhere have a line like self.assertEqual(..., 4.0)


def test_int_marker_size(self):
# Create some data
numpts = 50
x = sort(random(numpts))
y = random(numpts)

# Create a plot data object and give it this data
pd = ArrayPlotData()
pd.set_data("index", x)
pd.set_data("value", y)

# Create the plot
plot = Plot(pd, use_backbuffer=True, auto_grid=False)

plot.plot_1d(
"value",
type="scatter_1d",
orientation="v",
marker="plus",
alignment="left",
marker_size=5
)

def test_float_marker_size(self):
# Create some data
numpts = 50
x = sort(random(numpts))
y = random(numpts)

# Create a plot data object and give it this data
pd = ArrayPlotData()
pd.set_data("index", x)
pd.set_data("value", y)

# Create the plot
plot = Plot(pd, use_backbuffer=True, auto_grid=False)

plot.plot_1d(
"value",
type="scatter_1d",
orientation="v",
marker="plus",
alignment="left",
marker_size=5.0
)

def test_int_arr_marker_size(self):
# Create some data
numpts = 50
x = sort(random(numpts))
y = random(numpts)

# Create a plot data object and give it this data
pd = ArrayPlotData()
pd.set_data("index", x)
pd.set_data("value", y)

# Create the plot
plot = Plot(pd, use_backbuffer=True, auto_grid=False)

plot.plot_1d(
"value",
type="scatter_1d",
orientation="v",
marker="plus",
alignment="left",
marker_size=randint(1, 5, numpts)
)

def test_float_arr_marker_size(self):
# Create some data
numpts = 50
x = sort(random(numpts))
y = random(numpts)

# Create a plot data object and give it this data
pd = ArrayPlotData()
pd.set_data("index", x)
pd.set_data("value", y)

# Create the plot
plot = Plot(pd, use_backbuffer=True, auto_grid=False)

plot.plot_1d(
"value",
type="scatter_1d",
orientation="v",
marker="plus",
alignment="left",
marker_size=uniform(1, 5, numpts)
)