Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transfer Excel data I/O from message_ix #286

Closed
wants to merge 37 commits into from

Conversation

khaeru
Copy link
Member

@khaeru khaeru commented Mar 20, 2020

Replaced by #289.

@khaeru khaeru added the enh New features & functionality label Mar 20, 2020
@khaeru khaeru added this to the 3.0 milestone Mar 20, 2020
@khaeru khaeru self-assigned this Mar 20, 2020
- TimeSeries.read_file: new method.
- TimeSeries.add_timeseries: add a `year_lim` argument, so limiting
  data by year can be done even when not reading from file.
- core.to_iamc_template: rename to core.to_iamc_layout, update
  docstring, remove duplicate set computation.
- Simplify cli.import_timeseries.
- Update docs.
@khaeru
Copy link
Member Author

khaeru commented Mar 21, 2020

@zikolach as of the last commit here (b35889b), tests pass on all platforms and versions except Python 3.6 (i.e. 3.7 passes) on AppVeyor/Windows, where I see:

_________________________ TestScenario.test_excel_io __________________________
self = <test_scenario.TestScenario object at 0x000000535186F1D0>
scen = <ixmp.core.Scenario object at 0x000000535185E908>
scen_empty = <ixmp.core.Scenario object at 0x0000005351875438>
tmp_path = WindowsPath('C:/Users/appveyor/AppData/Local/Temp/1/pytest-of-appveyor/pytest-0/test_excel_io1/output.xlsx')
    def test_excel_io(self, scen, scen_empty, tmp_path):
        tmp_path /= 'output.xlsx'
    
        # FIXME remove_solution, check_out, commit, solve, commit should not
        #       be needed to make this small data addition.
        scen.remove_solution()
        scen.check_out()
        # A 1-D set indexed by another set
        scen.init_set('foo', 'j')
        scen.add_set('foo', [['new-york'], ['topeka']])
        # A scalar parameter with unusual units
        scen.platform.add_unit('pounds')
        scen.init_scalar('bar', 100, 'pounds')
        scen.commit('')
        scen.solve()
    
        # Solved Scenario can be written to file
        scen.to_excel(tmp_path)
    
        # With init_items=False, can't be read into an empty Scenario
        with pytest.raises(ValueError, match="no set 'i'; "
                                             "try init_items=True"):
            scen_empty.read_excel(tmp_path)
    
        # File can be read with init_items=False
>       scen_empty.read_excel(tmp_path, init_items=True, commit_steps=True)
..\..\ixmp\tests\core\test_scenario.py:221: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\..\ixmp\core.py:1515: in read_excel
    commit_steps=commit_steps,
..\..\ixmp\backend\jdbc.py:307: in read_file
    super().read_file(path, item_type, **kwargs)
..\..\ixmp\backend\base.py:274: in read_file
    s_read_excel(self, s, path, **kwargs)
..\..\ixmp\backend\io.py:178: in s_read_excel
    s.commit(f'Loaded sets from {path}')
..\..\ixmp\core.py:441: in commit
    self._backend('commit', comment)
..\..\ixmp\core.py:417: in _backend
    return self.platform._backend(self, method, *args, **kwargs)
..\..\ixmp\backend\base.py:22: in __call__
    return getattr(self, method)(obj, *args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <ixmp.backend.jdbc.JDBCBackend object at 0x00000053523EBE10>
ts = <ixmp.core.Scenario object at 0x0000005351875438>
comment = 'Loaded sets from C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\pytest-of-appveyor\\pytest-0\\test_excel_io1\\output.xlsx'
    def commit(self, ts, comment):
>       self.jindex[ts].commit(comment)
E       jpype._jclass.at.ac.iiasa.ixmp.exceptions.IxException: at.ac.iiasa.ixmp.exceptions.IxException: Wrong status AVAILABLE_IN_DB specified for run -1 or run not found!
..\..\ixmp\backend\jdbc.py:450: at.ac.iiasa.ixmp.exceptions.IxException

Do you have any intuition about what this means or why it only occurs in this one circumstance? I've tried restarting the test, but same result.

@zikolach
Copy link
Contributor

@khaeru it looks strange, based on exception we can conclude that scenario was not saved to DB (run id equals -1) when it calls checkIn method (as final step of commit call, when scenario should be already committed). In principle that is only possible when something went wrong committing scenario and failed in exception block, but then we should see message There was a problem writing data to the database with stack trace in the output. Could it be that pytest somehow hides/truncates the output?

@zikolach
Copy link
Contributor

zikolach commented Mar 23, 2020

Updated jar. Let's see what the output will be now

@khaeru
Copy link
Member Author

khaeru commented Mar 23, 2020

Closing in favour of #289.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enh New features & functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants