From 4bececd7f0ce7517492a8ebeddbf39211960fdfb Mon Sep 17 00:00:00 2001 From: Paul Natsuo Kishimoto Date: Sun, 21 Feb 2021 10:56:34 +0100 Subject: [PATCH] Reflow comments and docstrings in ixmp.core and tests --- ixmp/core.py | 35 +++++++++++++++--------------- ixmp/tests/core/test_platform.py | 8 +++---- ixmp/tests/core/test_timeseries.py | 15 ++++++------- 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/ixmp/core.py b/ixmp/core.py index 41571ed18..a9b331df8 100644 --- a/ixmp/core.py +++ b/ixmp/core.py @@ -343,24 +343,23 @@ def add_region_synonym(self, region, mapped_to): def timeslices(self): """Return all subannual timeslices defined in this Platform instance. - Timeslices are a way to represent subannual temporal resolution in - timeseries data. A timeslice consists of a **name** (e.g., 'january', - 'summer'), a **category** (e.g., 'months', 'seasons'), and a - **duration** given relative to a full year. - - The category and duration do not have any functional relevance within - the ixmp framework, but they may be useful for pre- or post-processing. - For example, they can be used to filter all timeslices of a certain - category (e.g., all months) from the :class:`pandas.DataFrame` returned - by this function or to aggregate subannual data to full-year results. - - A timeslice is related to the index set 'time' - in a :class:`message_ix.Scenario` to indicate a subannual temporal - dimension. Alas, timeslices and set elements of time have to be - initialized/defined independently. - - See :meth:`add_timeslice` to initialize additional timeslices in the - Platform instance. + Timeslices are a way to represent subannual temporal resolution in timeseries + data. A timeslice consists of a **name** (e.g., 'january', 'summer'), a + **category** (e.g., 'months', 'seasons'), and a **duration** given relative to a + full year. + + The category and duration do not have any functional relevance within the ixmp + framework, but they may be useful for pre- or post-processing. For example, + they can be used to filter all timeslices of a certain category (e.g., all + months) from the :class:`pandas.DataFrame` returned by this function or to + aggregate subannual data to full-year results. + + A timeslice is related to the index set 'time' in a :class:`message_ix.Scenario` + to indicate a subannual temporal dimension. Alas, timeslices and set elements of + time have to be initialized/defined independently. + + See :meth:`add_timeslice` to initialize additional timeslices in the Platform + instance. Returns ------- diff --git a/ixmp/tests/core/test_platform.py b/ixmp/tests/core/test_platform.py index 22b9494e9..1838e3886 100644 --- a/ixmp/tests/core/test_platform.py +++ b/ixmp/tests/core/test_platform.py @@ -343,16 +343,16 @@ def test_weakref(): # Make a local reference to the backend backend = mp._backend - # Delete the Platform. Note that this only has an effect if there are no - # existing references to it + # Delete the Platform. Note that this only has an effect if there are no existing + # references to it del mp # s.platform is a dead weak reference, so it can't be accessed with pytest.raises(ReferenceError): s.platform._backend - # There is only one remaining reference to the backend: the *backend* name - # in the local scope + # There is only one remaining reference to the backend: the *backend* name in the + # local scope assert getrefcount(backend) - 1 == 1 # The backend is garbage-collected at this point diff --git a/ixmp/tests/core/test_timeseries.py b/ixmp/tests/core/test_timeseries.py index 2aed09035..c9c5bb8c6 100644 --- a/ixmp/tests/core/test_timeseries.py +++ b/ixmp/tests/core/test_timeseries.py @@ -10,8 +10,8 @@ from ixmp.core import IAMC_IDX # Test data. -# NB the columns are in a specific order; model and scenario come last in the -# data returned by ixmp. +# NB the columns are in a specific order; model and scenario come last in the data +# returned by ixmp. # TODO fix this; model and scenario should come first, matching the IAMC order. DATA = { 0: pd.DataFrame.from_dict( @@ -56,8 +56,8 @@ scenario="scenario name", ) ), - # NB the columns for geodata methods are inconsistent with those for time- - # series data + # NB the columns for geodata methods are inconsistent with those for time-series + # data "geo": pd.DataFrame.from_dict( dict( region="World", @@ -132,10 +132,9 @@ def transact(ts, condition=True, commit_message=""): # Tests of ixmp.TimeSeries. # -# Since Scenario is a subclass of TimeSeries, all TimeSeries functionality -# should work exactly the same way on Scenario instances. The *ts* fixture is -# parametrized to yield both TimeSeries and Scenario objects, so every test -# is run on each type. +# Since Scenario is a subclass of TimeSeries, all TimeSeries functionality should work +# exactly the same way on Scenario instances. The *ts* fixture is parametrized to yield +# both TimeSeries and Scenario objects, so every test is run on each type. @pytest.fixture(scope="function", params=[TimeSeries, Scenario])