-
Notifications
You must be signed in to change notification settings - Fork 99
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
Conversation
close issue #846 |
chaco/plots/scatterplot_1d.py
Outdated
marker_size = Float(4.0) | ||
marker_size = Union(Float, Int, | ||
Array(Float), Array(Int), | ||
default_value=None) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
chaco/plots/scatterplot_1d.py
Outdated
@@ -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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
chaco/plots/scatterplot_1d.py
Outdated
@@ -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, | |||
Array(Float), Array(Int), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, thanks!
@homosapien-lcy as next step, we discussed:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@homosapien-lcy some comments to address on the test.
chaco/plots/scatterplot_1d.py
Outdated
@@ -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(float), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make the keyword argument explicit with dtype=float
chaco/tests/test_scatter_1d.py
Outdated
|
||
|
||
class Scatter1DTestCase(unittest.TestCase): | ||
# test the default value 4.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that comment line can be removed in favour of a clear method name or moved as a docstring to the test method.
chaco/tests/test_scatter_1d.py
Outdated
|
||
class Scatter1DTestCase(unittest.TestCase): | ||
# test the default value 4.0 | ||
def test_default(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggests test_default_marker_size
rather than test_default
chaco/tests/test_scatter_1d.py
Outdated
orientation="v", | ||
marker="plus", | ||
alignment="left" | ||
) |
There was a problem hiding this comment.
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? ...
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
chaco/tests/test_scatter_1d.py
Outdated
) | ||
|
||
# test integer marker size | ||
def test_int(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment on the method name and the removal of the comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comments, updates made
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really sure what the point of this PR is. The 1D scatterplot doesn't currently support variable size markers (or variable color or shape, for that matter). It could, potentially, but it doesn't right now, and this PR is not correct in its approach. Chaco is a dynamoc plotting library and all data needs to be passed via appropriate objects that manage changes to the data. For example, the example usage will fail if the using code changes the size of the data array holding the values.
To be fair, it looks like there is an error in the corresponding Trait declarations for the 2D scatterplot: the following is not correct either (edit: as is noted in the "TODO")
chaco/chaco/plots/scatterplot.py
Lines 228 to 231 in f32e01c
# The pixel size of the markers, not including the thickness of the outline. | |
# Default value is 4.0. | |
# TODO: for consistency, there should be a size data source and a mapper | |
marker_size = Union(Float, Array, requires_redraw=True) |
A correct implementation would use a data source for the sizes (and possibly a mapper as well), the way that the colormapped scatterplot does for colors:
chaco/chaco/plots/colormapped_scatterplot.py
Lines 65 to 66 in f32e01c
#: Source for color data. | |
color_data = Instance(ArrayDataSource) |
It would also have to add support for finding the data source in the Plot
object code, eg. somewhere in here:
Lines 1270 to 1296 in f32e01c
if plot_type in ("scatter_1d", "line_scatter_1d", "jitterplot"): | |
# simple 1d positional plots with no associated value | |
for source in data: | |
index = self._get_or_create_datasource(source) | |
index_range.add(index) | |
if scale == "linear": | |
imap = LinearMapper( | |
range=index_range, | |
stretch_data=index_mapper.stretch_data, | |
) | |
else: | |
imap = LogMapper( | |
range=index_range, | |
stretch_data=index_mapper.stretch_data, | |
) | |
cls = self.renderer_map[plot_type] | |
plot = cls( | |
index=index, | |
index_mapper=imap, | |
orientation=orientation, | |
direction=direction, | |
**styles | |
) | |
plots.append(plot) | |
self.add(plot) |
chaco/plots/scatterplot_1d.py
Outdated
marker_size = Union(Float, | ||
Array(dtype=float), | ||
default_value=4.0) |
There was a problem hiding this comment.
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)
.
orientation="v", | ||
marker="plus", | ||
alignment="left", | ||
marker_size=randint(1,5, numpts) |
There was a problem hiding this comment.
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.
chaco/tests/test_scatter_1d.py
Outdated
orientation="v", | ||
marker="plus", | ||
alignment="left" | ||
) |
There was a problem hiding this comment.
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)
chaco/tests/test_scatter_1d.py
Outdated
# Thanks for using Enthought open source! | ||
|
||
""" | ||
Unit tests for scatter_1d function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are already tests for the 1D scatterplot here: https://github.com/enthought/chaco/blob/main/chaco/plots/tests/test_scatterplot_1d.py
With Corran's comments, after discussing with Didrik, we think: 1 the "error" that the user reported in #846 is actually the expected behavior of the test, thus there is no need to change the scatterplot class to enable different types of inputs With the above observations, we decided to simply delete the commented out line mentioned in 2 to avoid confusion as the solution to the issue closes #846 |
The ScatterPlot1D specifies marker_size = Float(4.0) while the downstream render_markers function is supposed to handle both single numeric data and arrays. This PR changes this.
Address #846