Deltares / imod-qgis

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

Time Series widget cannot handle non-existing and empty arrow files #64

Closed deltamarnix closed 6 months ago

deltamarnix commented 9 months ago

I have a layer where the elements contain an arrow_path that I put in via python.

layer.setCustomProperty("arrow_type", "timeseries")
layer.setCustomProperty("arrow_path", str(path))
layer.setCustomProperty("arrow_fid_column", column)

When the layer is read by the time series widget, it cannot handle it when the path is non-existent, or the data is empty. Non-existent gives the following error.

An error has occurred while executing Python code:

AttributeError: 'NoneType' object has no attribute 'GetLayer' 
Traceback (most recent call last):
  File "C:\Users/X/Source/Repos/Ribasim/.pixi/env/Library/./python/plugins\imodqgis\imod_plugin.py", line 132, in toggle_timeseries
    widget = ImodTimeSeriesWidget(self.timeseries_widget, self.iface)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users/X/Source/Repos/Ribasim/.pixi/env/Library/./python/plugins\imodqgis\timeseries\timeseries_widget.py", line 284, in __init__
    self.on_layer_changed()
  File "C:\Users/X/Source/Repos/Ribasim/.pixi/env/Library/./python/plugins\imodqgis\timeseries\timeseries_widget.py", line 464, in on_layer_changed
    self.load_arrow_data(layer)
  File "C:\Users/X/Source/Repos/Ribasim/.pixi/env/Library/./python/plugins\imodqgis\timeseries\timeseries_widget.py", line 548, in load_arrow_data
    df = read_arrow(arrow_path)
         ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users/X/Source/Repos/Ribasim/.pixi/env/Library/./python/plugins\imodqgis\arrow\reading.py", line 7, in read_arrow
    layer = dataset.GetLayer(0)
            ^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'GetLayer'

Python version: 3.11.6 | packaged by conda-forge | (main, Oct  3 2023, 10:29:11) [MSC v.1935 64 bit (AMD64)] 
QGIS version: 3.28.12-Firenze Firenze, exported