Deltares / imod-qgis

🗺️🧭 QGIS plugin for iMOD
GNU General Public License v2.0
7 stars 1 forks source link

Don't error if Arrow files don't exist or are empty #69

Closed visr closed 6 months ago

visr commented 6 months ago

Fix #64.

When opening a Ribasim model and you don't know there is no output yet, but click the time series widget, you get an error that is hard to understand.

This changes the code to not load any data, such that the widget still opens but there are no variables to select. If you then run the model and load the widget again the results do appear. It is better than the current behavior, though I'm also open to other ways to handle this.

This was the error when it did not exist:

AttributeError: 'NoneType' object has no attribute 'GetLayer' 
Traceback (most recent call last):
  File "C:\Users/visser_mn/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\imodqgis\imod_plugin.py", line 132, in toggle_timeseries
    widget = ImodTimeSeriesWidget(self.timeseries_widget, self.iface)
  File "C:\Users/visser_mn/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\imodqgis\timeseries\timeseries_widget.py", line 284, in __init__
    self.on_layer_changed()
  File "C:\Users/visser_mn/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\imodqgis\timeseries\timeseries_widget.py", line 464, in on_layer_changed
    self.load_arrow_data(layer)
  File "C:\Users/visser_mn/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\imodqgis\timeseries\timeseries_widget.py", line 548, in load_arrow_data
    df = read_arrow(arrow_path)
  File "C:\Users/visser_mn/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\imodqgis\arrow\reading.py", line 7, in read_arrow
    layer = dataset.GetLayer(0)
AttributeError: 'NoneType' object has no attribute 'GetLayer'

And when it was empty it got a KeyError for edge_id in the groupby.

visr commented 6 months ago

The last commit, 23b3d441b4fd2722918421ed8d5b4040c8237818, is unrelated, but a quick usability win. We have a bunch of string and integer columns, and never want to plot timeseries of those. This commit only leaves the ones we care about as options to select.