jamshid
unread,Nov 18, 2023, 11:38:15 AM11/18/23Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to MUSE
Dear Sara and MUSE team,
I get KeyError: Year, while MUSE "foresight" is not equal to 5.
Error raises from "get_loc" method of pandas, when trying to get integer location.
It can be replicated using "default_timeslice" folder with the following values in the toml file.
time_framework = [2020, 2026, 2032, ...]
foresight = 6
In this case the KeyError will be 2021, if you will try a different value (except 5) for foresight you will get "another year" in the error.
I'm using pandas==1.3.0 and xarray==2022.3.0
Below is the error message.
Traceback (most recent call last):
File "...\.venv\lib\site-packages\pandas\core\indexes\base.py", line 3361, in get_loc
return self._engine.get_loc(casted_key)
File "pandas\_libs\index.pyx", line 76, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\index.pyx", line 108, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\hashtable_class_helper.pxi", line 2131, in pandas._libs.hashtable.Int64HashTable.get_item
File "pandas\_libs\hashtable_class_helper.pxi", line 2140, in pandas._libs.hashtable.Int64HashTable.get_item
KeyError: 20..
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "...\my_code.py", line 30, in <module>
run_muse()
File "...\.venv\lib\site-packages\muse\mca.py", line 364, in run
self.outputs(
File "...\.venv\lib\site-packages\muse\outputs\sector.py", line 106, in save_multiple_outputs
return [
File "...\.venv\lib\site-packages\muse\outputs\sector.py", line 107, in <listcomp>
sink(quantity(market, *args), year=year)
File "...\.venv\lib\site-packages\muse\registration.py", line 172, in decorated
result = inner_decorated(*args, **kwargs)
File "...\.venv\lib\site-packages\muse\outputs\mca.py", line 67, in decorated
result = function(*args, **kwargs)
File "...\.venv\lib\site-packages\muse\outputs\mca.py", line 344, in metric_supply
return _aggregate_sectors(sectors, market_out, op=sector_supply)
File "...\.venv\lib\site-packages\muse\outputs\mca.py", line 250, in _aggregate_sectors
alldata = [op(sector, *args) for sector in sectors]
File "...\.venv\lib\site-packages\muse\outputs\mca.py", line 250, in <listcomp>
alldata = [op(sector, *args) for sector in sectors]
File "...\.venv\lib\site-packages\muse\outputs\mca.py", line 360, in sector_supply
agent_market = market.sel(year=output_year).copy()
File "...\.venv\lib\site-packages\xarray\core\dataset.py", line 2501, in sel
pos_indexers, new_indexes = remap_label_indexers(
File "...\.venv\lib\site-packages\xarray\core\coordinates.py", line 421, in remap_label_indexers
pos_indexers, new_indexes = indexing.remap_label_indexers(
File "...\.venv\lib\site-packages\xarray\core\indexing.py", line 121, in remap_label_indexers
idxr, new_idx = index.query(labels, method=method, tolerance=tolerance)
File "...\.venv\lib\site-packages\xarray\core\indexes.py", line 241, in query
indexer = self.index.get_loc(label_value)
File "...\.venv\lib\site-packages\pandas\core\indexes\base.py", line 3363, in get_loc
raise KeyError(key) from err
KeyError: 20..
Regards,
Jamshid