Problem Description
Removing a data source from a DataView instance leaves it internally inconsistent.
Reproduction Steps:
This snippet demonstrates the inconsistency:
import numpy as np
from chaco.api import DataView
from chaco.grid_data_source import GridDataSource
source = GridDataSource(xdata=np.array([1, 2, 4]), ydata=np.array([7, 8, 9]))
component = DataView()
print(f"Initial output: {component.map_screen(np.array([0, 1]))}")
component.range2d.add(source) # (1)
component.map_screen(np.array([0, 1])) # (2)
component.range2d.remove(source) # (3)
print(f"Final output: {component.map_screen(np.array([0, 1]))}")
Output:
Initial output: [[0. 0.]]
Final output: [inf inf]
Initially, without any data sources, the output of component.map_screen is [[0, 0]]. When a data source is added and then removed, the bounds on component.value_mapper.range to refreshed to (-inf, inf). However, component.value_mapper._cache_valid isn't reverted from True to False. (It's set to True as a consequence of (2) in the snippet above.) As a result, subsequent calls to component.map_screen produce infs. This infs in turn have the potential to turn into nans, raising exceptions in unexpected places downstream.
Expected behavior:
I think the output should be [[0., 0.]] again, (or more precisely, component.value_mapper._cache_valid should revert to False if component.value_mapper.range.refresh() is called. However, I'm not sure and opening this issue for discussion.
OS, Python version: macOS Catalina 10.15.7, Python 3.6.13
Problem Description
Removing a data source from a
DataViewinstance leaves it internally inconsistent.Reproduction Steps:
This snippet demonstrates the inconsistency:
Output:
Initially, without any data sources, the output of
component.map_screenis[[0, 0]]. When a data source is added and then removed, the bounds oncomponent.value_mapper.rangeto refreshed to (-inf, inf). However,component.value_mapper._cache_validisn't reverted fromTruetoFalse. (It's set toTrueas a consequence of (2) in the snippet above.) As a result, subsequent calls tocomponent.map_screenproduceinfs. Thisinfs in turn have the potential to turn intonans, raising exceptions in unexpected places downstream.Expected behavior:
I think the output should be [[0., 0.]] again, (or more precisely,
component.value_mapper._cache_validshould revert toFalseifcomponent.value_mapper.range.refresh()is called. However, I'm not sure and opening this issue for discussion.OS, Python version: macOS Catalina 10.15.7, Python 3.6.13