chaco icon indicating copy to clipboard operation
chaco copied to clipboard

auto_ticks raises ValueError for some inputs

Open mdickinson opened this issue 3 years ago • 4 comments

We're running into the following problem with auto_ticks on a downstream project, leading to a blank plot window.

Python 3.6.13 |Enthought, Inc. (x86_64)| (default, Apr 13 2021, 19:22:11) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from chaco.ticks import auto_ticks
>>> auto_ticks(657022.2328451854, 577935.6054180114, 657022.2328451854, 577935.6054180114, "auto", use_endpoints=False)
/Users/mdickinson/Enthought/ETS/chaco/chaco/ticks.py:392: RuntimeWarning: invalid value encountered in log10
  magnitudes = 10.0 ** floor(log10(candidate_intervals))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/mdickinson/Enthought/ETS/chaco/chaco/ticks.py", line 308, in auto_ticks
    ticks = arange(start, end + (tick_interval / 2.0), tick_interval)
ValueError: arange: cannot compute length

Expected behaviour: a list of tick locations is returned (possibly the empty list).

mdickinson avatar Jan 21 '22 15:01 mdickinson

Note that we have data_low > data_high for the inputs to auto_ticks above. While this may be indicative of an error in the calling code, I think it would make sense to also make auto_ticks robust for this kind of input.

mdickinson avatar Jan 21 '22 15:01 mdickinson

Not a fix, but a work-around: if you can create a replacement without the error, it is straightforward to create a new tick generator around the replacement and use that in the downstream app.

corranwebster avatar Jan 21 '22 15:01 corranwebster

Also, separately, this feels like it is a symptom, not the root cause: the axis bounds being inverted smells like there a problem with the values being passed to the ticking system. In particular, are we in a situation where the width (or height, depending on orientation) of the axis component is negative? If so, then all sorts of things may be messed up beyond ticking.

corranwebster avatar Jan 21 '22 16:01 corranwebster

FWIW - This same traceback was seen a while back: https://github.com/enthought/chaco/issues/529 and that issue was closed by https://github.com/enthought/chaco/pull/636 but 636 was just checking for NaN inputs, not non-NaN inputs that could lead to NaNs inside the method

In this case, tick_interval on this line ends up as NaN https://github.com/enthought/chaco/blob/0907d1dedd07a499202efbaf2fe2a4e51b4c8e5f/chaco/ticks.py#L272 and that is because log10 is getting negative inputs here https://github.com/enthought/chaco/blob/0907d1dedd07a499202efbaf2fe2a4e51b4c8e5f/chaco/ticks.py#L392

aaronayres35 avatar Jan 21 '22 16:01 aaronayres35

Tentatively closing as this should be resolved (at least in the sense of treating the symptoms) by #848

corranwebster avatar May 12 '23 15:05 corranwebster