-
Notifications
You must be signed in to change notification settings - Fork 69
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Version Checks (indicate both or one)
-
I have confirmed this bug exists on the lastest release of Linopy.
-
I have confirmed this bug exists on the current
masterbranch of Linopy.
Issue Description
One of the tests is failing on my machine. Probably not a serious problem, but worth reporting i thought.
Reproducible Example
pytest test/test_io.py::test_model_to_netcdf_with_multiindexReturns:
================================================================================= FAILURES =================================================================================
___________________________________________________________________ test_model_to_netcdf_with_multiindex ___________________________________________________________________
model_with_multiindex = Linopy LP model
===============
Variables:
----------
* x-var (dim_0, first, second)
* y-var (dim_0, first, second, dim_1)
Constraints:
------------
* constraint-1 (dim_0, first, second, dim_1)
Status:
-------
initialized
tmp_path = PosixPath('/private/var/folders/2s/46_0tgfd5gq5kkpx7k42xr_w0000gn/T/pytest-of-felix/pytest-11/test_model_to_netcdf_with_mult0')
@pytest.mark.skipif(
xr.__version__ in ["2024.1.0", "2024.1.1"],
reason="xarray version 2024.1.0 has a bug with MultiIndex deserialize",
)
def test_model_to_netcdf_with_multiindex(
model_with_multiindex: Model, tmp_path: Path
) -> None:
m = model_with_multiindex
fn = tmp_path / "test.nc"
> m.to_netcdf(fn)
test/test_io.py:137:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.venv/lib/python3.11/site-packages/linopy/io.py:935: in to_netcdf
ds.to_netcdf(*args, **kwargs)
.venv/lib/python3.11/site-packages/xarray/core/dataset.py:2110: in to_netcdf
return to_netcdf( # type: ignore[return-value] # mypy cannot resolve the overloads:(
.venv/lib/python3.11/site-packages/xarray/backends/writers.py:455: in to_netcdf
store.close()
.venv/lib/python3.11/site-packages/xarray/backends/scipy_.py:312: in close
self._manager.close()
.venv/lib/python3.11/site-packages/xarray/backends/file_manager.py:242: in close
file.close()
.venv/lib/python3.11/site-packages/scipy/io/_netcdf.py:298: in close
self.flush()
.venv/lib/python3.11/site-packages/scipy/io/_netcdf.py:411: in flush
self._write()
.venv/lib/python3.11/site-packages/scipy/io/_netcdf.py:422: in _write
self._write_gatt_array()
.venv/lib/python3.11/site-packages/scipy/io/_netcdf.py:444: in _write_gatt_array
self._write_att_array(self._attributes)
.venv/lib/python3.11/site-packages/scipy/io/_netcdf.py:452: in _write_att_array
self._write_att_values(values)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <scipy.io._netcdf.netcdf_file object at 0x11feeb510>, values = array(['first', 'second'], dtype='<U6')
def _write_att_values(self, values):
if hasattr(values, 'dtype'):
> nc_type = REVERSE[values.dtype.char, values.dtype.itemsize]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E KeyError: ('U', 24)
.venv/lib/python3.11/site-packages/scipy/io/_netcdf.py:565: KeyError
========================================================================= short test summary info ==========================================================================
FAILED test/test_io.py::test_model_to_netcdf_with_multiindex - KeyError: ('U', 24)
Expected Behavior
PASSED
Installed Versions
Details
accessible-pygments==0.0.5 alabaster==0.7.16 appnope==0.1.4 asttokens==3.0.1 attrs==25.4.0 babel==2.17.0 beautifulsoup4==4.14.2 bleach==6.3.0 bottleneck==1.6.0 cachetools==6.2.2 certifi==2025.11.12 charset-normalizer==3.4.4 click==8.3.1 cloudpickle==3.1.2 comm==0.2.3 contourpy==1.3.3 cycler==0.12.1 dask==2025.11.0 debugpy==1.8.17 decorator==5.2.1 defusedxml==0.7.1 deprecation==2.1.0 docutils==0.20.1 executing==2.2.1 fastjsonschema==2.21.2 fonttools==4.60.1 fsspec==2025.10.0 google-api-core==2.28.1 google-auth==2.43.0 google-cloud-core==2.5.0 google-cloud-storage==3.6.0 google-crc32c==1.7.1 google-resumable-media==2.8.0 googleapis-common-protos==1.72.0 gurobipy==11.0.2 idna==3.11 imagesize==1.4.1 importlib-metadata==8.7.0 iniconfig==2.3.0 ipykernel==6.29.5 ipython==8.26.0 jedi==0.19.2 jinja2==3.1.6 jsonschema==4.25.1 jsonschema-specifications==2025.9.1 jupyter-client==8.6.3 jupyter-core==5.9.1 jupyterlab-pygments==0.3.0 kiwisolver==1.4.9 linopy @ file:///Users/felix/PycharmProjects/linopy_3 locket==1.0.0 markupsafe==3.0.3 matplotlib==3.9.1 matplotlib-inline==0.2.1 mistune==3.1.4 nbclient==0.10.2 nbconvert==7.16.6 nbformat==5.10.4 nbsphinx==0.9.4 nbsphinx-link==1.3.0 nest-asyncio==1.6.0 numexpr==2.14.1 numpy==1.26.4 numpydoc==1.7.0 packaging==25.0 pandas==2.3.3 pandocfilters==1.5.1 parso==0.8.5 partd==1.4.2 pexpect==4.9.0 pillow==12.0.0 platformdirs==4.5.0 pluggy==1.6.0 polars==1.35.2 polars-runtime-32==1.35.2 prompt-toolkit==3.0.52 proto-plus==1.26.1 protobuf==6.33.1 psutil==7.1.3 ptyprocess==0.7.0 pure-eval==0.2.3 pyasn1==0.6.1 pyasn1-modules==0.4.2 pydata-sphinx-theme==0.16.1 pygments==2.19.2 pyparsing==3.2.5 pytest==9.0.1 python-dateutil==2.9.0.post0 pytz==2025.2 pyyaml==6.0.3 pyzmq==27.1.0 referencing==0.37.0 requests==2.32.5 rpds-py==0.29.0 rsa==4.9.1 scipy==1.16.3 six==1.17.0 snowballstemmer==3.0.1 soupsieve==2.8 sphinx==7.3.7 sphinx-book-theme==1.1.3 sphinx-rtd-theme==2.0.0 sphinxcontrib-applehelp==2.0.0 sphinxcontrib-devhelp==2.0.0 sphinxcontrib-htmlhelp==2.1.0 sphinxcontrib-jquery==4.1 sphinxcontrib-jsmath==1.0.1 sphinxcontrib-qthelp==2.0.0 sphinxcontrib-serializinghtml==2.0.0 stack-data==0.6.3 tabulate==0.9.0 tinycss2==1.4.0 toolz==1.1.0 tornado==6.5.2 tqdm==4.67.1 traitlets==5.14.3 typing-extensions==4.15.0 tzdata==2025.2 urllib3==2.5.0 wcwidth==0.2.14 webencodings==0.5.1 xarray==2025.11.0 zipp==3.23.0Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working