MAINT: fix marker size type mismatch error#859
Conversation
|
close issue #846 |
| marker_size = Float(4.0) | ||
| marker_size = Union(Float, Int, | ||
| Array(Float), Array(Int), | ||
| default_value=None) |
There was a problem hiding this comment.
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.
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.
@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 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.
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.
Yeah, I found that Float trait can accomodate int as well, just cahnged.
| # 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.
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.
Got it, thanks!
|
@homosapien-lcy as next step, we discussed:
|
dpinte
left a comment
There was a problem hiding this comment.
@homosapien-lcy some comments to address on the test.
| # 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.
make the keyword argument explicit with dtype=float
|
|
||
|
|
||
| class Scatter1DTestCase(unittest.TestCase): | ||
| # test the default value 4.0 |
There was a problem hiding this comment.
that comment line can be removed in favour of a clear method name or moved as a docstring to the test method.
|
|
||
| class Scatter1DTestCase(unittest.TestCase): | ||
| # test the default value 4.0 | ||
| def test_default(self): |
There was a problem hiding this comment.
I would suggests test_default_marker_size rather than test_default
| orientation="v", | ||
| marker="plus", | ||
| alignment="left" | ||
| ) |
There was a problem hiding this comment.
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.
that is applicable to all the tests.
There was a problem hiding this comment.
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.
If this is a test of the default marker size, you should somewhere have a line like self.assertEqual(..., 4.0)
| ) | ||
|
|
||
| # test integer marker size | ||
| def test_int(self): |
There was a problem hiding this comment.
same comment on the method name and the removal of the comment
There was a problem hiding this comment.
Thanks for the comments, updates made
There was a problem hiding this comment.
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
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
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
| marker_size = Union(Float, | ||
| Array(dtype=float), | ||
| default_value=4.0) |
There was a problem hiding this comment.
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.
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.
| orientation="v", | ||
| marker="plus", | ||
| alignment="left" | ||
| ) |
There was a problem hiding this comment.
If this is a test of the default marker size, you should somewhere have a line like self.assertEqual(..., 4.0)
| # Thanks for using Enthought open source! | ||
|
|
||
| """ | ||
| Unit tests for scatter_1d function |
There was a problem hiding this comment.
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