IndEcol / pymrio

Multi-Regional Input-Output Analysis in Python.
http://pymrio.readthedocs.io/en/latest/
Other
158 stars 71 forks source link

#Bugs with Exiobase 2 #21

Closed bixiou closed 6 years ago

bixiou commented 6 years ago

There seems to be two issues with the handling of Exiobase 2 by pymrio. First, when the PxP IO system, which I call exio2p*, is reset, using the method reset_all_to_coefficients(), the matrices A and L are missing (I haven't tested it for IxI but it might be the same). Second, when one tries to use the method aggregate, an error is raised. If the method is called before calling .calc_all(), the error reads:

WARNING:root:No attributes available to get sectors
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-61-441d56c89f18> in <module>()
----> 1 global_io = exio2p.aggregate(region_agg = 'global', sector_agg='total', inplace=False)

~/anaconda3/lib/python3.5/site-packages/pymrio/core/mriosystem.py in aggregate(self, region_agg, sector_agg, region_names, sector_names, inplace, pre_aggregation)
   1659             region_agg = [region_agg] * len(self.get_regions())
   1660         if type(sector_agg) is str:
-> 1661             sector_agg = [sector_agg] * len(self.get_sectors())
   1662 
   1663         if ioutil.is_vector(region_agg):

TypeError: object of type 'NoneType' has no len()

whereas if ones applies .calc_all() first, the error is:

----> 1 global_io = exio2p.aggregate(region_agg = 'global', sector_agg='total', inplace=False)

~/anaconda3/lib/python3.5/site-packages/pymrio/core/mriosystem.py in aggregate(self, region_agg, sector_agg, region_names, sector_names, inplace, pre_aggregation)
   1752                         data=conc.dot(self.x),
   1753                         index=mi_reg_sec,
-> 1754                         columns=self.x.columns,
   1755                         )
   1756             self.meta._add_modify('Aggregate industry output x')

AttributeError: 'Series' object has no attribute 'columns'

Same errors are raised if other parameters are passed in the .aggregate() method (such as a more complicated aggregation).

*exio2p is defined as follows:

exio2p = pymrio.parse_exiobase2(path=[path to the PxP .zip], charact=True, popvector='exio2')
konstantinstadler commented 6 years ago

Mmm (currently on paternity leave, so just a quick thought): did you try calc_all() before you do reset_all_to_coefficients()

bixiou commented 6 years ago

Ok my bad, I am not unable to reproduce this bug. The second one remains, however.

konstantinstadler commented 6 years ago

Ok.

1) For the first case (aggregate before calc_all): the behavior is kind of correct (it should/can not work), but needs an user information/warning (When you dont have any absolute numbers, aggregation can not work). I will do that when I am back (#23) 2) For the second case. This is also a bug. You can work around that with (after calc_all but before the aggregation)

import pandas as pd
exio2p.x = pd.DataFrame(exio2p.x)

I will also fix that when I am back (#24)

Thanks for reporting this - it helps a lot. Sorry for not immediately fixing it, but currently otherwise occupied...

bixiou commented 6 years ago

Thank's a lot!

konstantinstadler commented 6 years ago

No problem

konstantinstadler commented 6 years ago

Both things are done now and available in the master branch. There are some more things I want to do before the next release to pypi and conda, but that should happen soon. Thanks again for the feedback!