calliope-project / calligraph

Calligraph: A tool to interactively explore and visualise Calliope model results
Apache License 2.0
4 stars 1 forks source link

Error '__array_struct__'with previously working envs #13

Closed FLomb closed 1 day ago

FLomb commented 2 days ago

Environments in which Calligraph was previously working are not failing due to the error reported below.

For example, in this env:

name: calliope_viz
channels:
    - conda-forge/label/calliope_dev
    - conda-forge
    - gurobi
dependencies:
    - python=3.12
    - matplotlib=3.5.2
    - jupyterlab
    - glpk=5.0
    - ipopt=3.14.9
    - gurobi=11.0
    - calliope=0.7.0dev4
    - pandas=1.4.3
    - pip
    - pyomo=6.4.1
    - pip:
        - calligraph==0.1.1dev2
Traceback (most recent call last):
  File "/home/fl/anaconda3/envs/calliope_dev_07/bin/calligraph", line 8, in <module>
    sys.exit(calligraph_cli())
  File "/home/fl/anaconda3/envs/calliope_dev_07/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/fl/anaconda3/envs/calliope_dev_07/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/fl/anaconda3/envs/calliope_dev_07/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/fl/anaconda3/envs/calliope_dev_07/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/fl/GitHub-repos/calligraph/src/calligraph/cli.py", line 23, in calligraph_cli
    app = calligraph.ui.app(path)
  File "/home/fl/GitHub-repos/calligraph/src/calligraph/ui.py", line 311, in app
    ui_view = UIView(model_container)
  File "/home/fl/GitHub-repos/calligraph/src/calligraph/ui.py", line 31, in __init__
    self.switch_page(list(self.pages.keys())[0])
  File "/home/fl/GitHub-repos/calligraph/src/calligraph/ui.py", line 254, in switch_page
    content = self.pages[page]["view"](self)
  File "/home/fl/GitHub-repos/calligraph/src/calligraph/pages.py", line 17, in page_home
    pn.pane.DataFrame(core.get_solve_config_df(model_container)),
  File "/home/fl/GitHub-repos/calligraph/src/calligraph/core.py", line 198, in get_solve_config_df
    df = pd.DataFrame.from_dict(results.attrs["config"]["solve"], orient="index")
  File "/home/fl/anaconda3/envs/calliope_dev_07/lib/python3.10/site-packages/pandas/core/frame.py", line 1917, in from_dict
    return cls(data, index=index, columns=columns, dtype=dtype)
  File "/home/fl/anaconda3/envs/calliope_dev_07/lib/python3.10/site-packages/pandas/core/frame.py", line 867, in __init__
    mgr = ndarray_to_mgr(
  File "/home/fl/anaconda3/envs/calliope_dev_07/lib/python3.10/site-packages/pandas/core/internals/construction.py", line 319, in ndarray_to_mgr
    values = _prep_ndarraylike(values, copy=copy_on_sanitize)
  File "/home/fl/anaconda3/envs/calliope_dev_07/lib/python3.10/site-packages/pandas/core/internals/construction.py", line 580, in _prep_ndarraylike
    values = convert(values)
  File "/home/fl/anaconda3/envs/calliope_dev_07/lib/python3.10/site-packages/pandas/core/internals/construction.py", line 564, in convert
    res = maybe_convert_platform(v)
  File "/home/fl/anaconda3/envs/calliope_dev_07/lib/python3.10/site-packages/pandas/core/dtypes/cast.py", line 130, in maybe_convert_platform
    arr = construct_1d_object_array_from_listlike(values)
  File "/home/fl/anaconda3/envs/calliope_dev_07/lib/python3.10/site-packages/pandas/core/dtypes/cast.py", line 1600, in construct_1d_object_array_from_listlike
    result[:] = values
KeyError: '__array_struct__'
brynpickering commented 2 days ago

Can I just check that the env you list the dependencies of us definitely the one throwing the error? Because it seems to be calling dependencies in the "calliope_dev_07" env.

brynpickering commented 2 days ago

Also, pandas 1.4.3 and pyomo 6.4.3 are both impossible to install alongside v0.7.0.dev4 of calliope (minimum 2.1.3 and 6.5, respectively). Can you run conda list in the env that you're seeing this error and report that result?

brynpickering commented 2 days ago

I cannot reproduce your error with the national scale example model generated in v0.7.0.dev4 and using the following env file:

env

```yaml name: calliope_viz channels: - conda-forge/label/calliope_dev - conda-forge - gurobi dependencies: - python=3.12 - matplotlib=3.8.2 - jupyterlab - glpk=5.0 - ipopt=3.14.9 - gurobi=11.0 - calliope=0.7.0dev4 - pandas=2.1.3 - pip - pyomo=6.7 - pip: - calligraph==0.1.1dev2 ```

FLomb commented 2 days ago

Ok, thanks for checking. It is true that I pasted an environment that contained some errors - those were my attempts at fixing the issue by downgrading some libraries, such as pandas.

I have created a new env with the specific you pasted above. I also do not get the error for the example national-scale model, but I do get the error for my (still quite simple) model. And I wasn't getting the problem before.

I attach it here: model.zip