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
Changes from 7 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
10 changes: 8 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, Int, 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, Int,
Copy link
Member

Choose a reason for hiding this comment

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

The Float trait should already accept integers, so I'm not sure that it adds much to accept Int here, especially given that the marker size is conceptually a float here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I found that Float trait can accomodate int as well, just cahnged.

Array(Float), Array(Int),
Copy link
Member

Choose a reason for hiding this comment

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

This isn't how the Array trait works - you need to supply a dtype as the argument, not a trait type. As it stands, this would accept an array with any dtype.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, thanks!

default_value=None)
Copy link
Member

Choose a reason for hiding this comment

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

Why changing the defaut to None? The 4.0 value was a good default. By changing the default, you now have to update the _render method.

The upstream issue was related to the fact that only floats were supported. Using a Union type, you now allow other data type, which is solving the problem. Adding a tests that reproduces the uptsream problem would be good

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I somehow remembered that using 4.0 as default will raise an error, but after retest, works fine... Will use 4.0 instead.

Copy link
Member

Choose a reason for hiding this comment

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

@homosapien-lcy adding a new manual example is not adding a test!
As discussed, tests are based on the unittest.TestCase in order too be picked up by the CI and shoud be added here: https://github.com/enthought/chaco/blob/main/chaco/plots/tests/test_scatterplot_1d.py


# 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 Expand Up @@ -111,6 +113,10 @@ def _draw_plot(self, gc, view_bounds=None, mode="normal"):
self._render(gc, pts)

def _render(self, gc, pts):
# check for None marker size and give a default value
if self.marker_size is None:
self.marker_size = 4.0

with gc:
gc.clip_to_rect(self.x, self.y, self.width, self.height)
if not self.index:
Expand Down