Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Next release

- [#989](https://github.com/IAMconsortium/pyam/pull/989) Add an `IamDataFrame.series` attribute to get timeseries data
as **pd.Series**

# Release v3.3.3

## Highlights
Expand Down
5 changes: 5 additions & 0 deletions pyam/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,11 @@ def data(self):
return pd.DataFrame([], columns=self.dimensions + ["value"])
return self._data.reset_index()

@property
def series(self):
"""Return the timeseries data as an indexed :class:`pandas.Series`"""
return self._data.copy()

def sort_data(self, inplace=False):
"""Sort timeseries data by index and coordinates

Expand Down
13 changes: 13 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,19 @@ def test_print_empty(test_df_year):
assert obs == exp


def test_pandas_types(test_df):

series = test_df.series
data = test_df.data

# assert that data and series yield the same result as different types
pdt.assert_frame_equal(series.reset_index(), data)

# check that `series` yields a copy and changes to not affect the IamDataFrame
series.iloc[0] = -2
pdt.assert_frame_equal(test_df.series.reset_index(), data)


def test_as_pandas(test_df):
# test that `as_pandas()` returns the right columns
df = test_df.copy()
Expand Down
Loading